@dtoolkit/dproxy 0.1.0 → 0.2.0
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 +79 -0
- package/dist/index.js +66 -66
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="../../logo.png" alt="dtoolkit" />
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<h1 align="center">@dtoolkit/dproxy</h1>
|
|
6
|
+
<p align="center">Universal CLI adapter for invoking models via local CLIs</p>
|
|
7
|
+
|
|
8
|
+
<p align="center">
|
|
9
|
+
<a href="https://www.npmjs.com/package/@dtoolkit/dproxy"><img src="https://img.shields.io/npm/v/@dtoolkit/dproxy.svg" alt="npm"></a>
|
|
10
|
+
<a href="../../LICENSE"><img src="https://img.shields.io/badge/License-MIT-blue.svg" alt="License"></a>
|
|
11
|
+
</p>
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install -g @dtoolkit/dproxy
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Quick start
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
dproxy init # interactive setup wizard
|
|
23
|
+
dproxy "explain this" # single-shot prompt
|
|
24
|
+
dproxy chat # interactive REPL
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Commands
|
|
28
|
+
|
|
29
|
+
| Command | Description |
|
|
30
|
+
| --- | --- |
|
|
31
|
+
| `dproxy init` | Interactive setup (required before first use) |
|
|
32
|
+
| `dproxy <prompt>` | Single-shot prompt (shorthand for `dproxy ask`) |
|
|
33
|
+
| `dproxy ask <prompt>` | Send a prompt with full context injection |
|
|
34
|
+
| `dproxy chat` | Interactive REPL with session tracking |
|
|
35
|
+
| `dproxy history` | List, show, search, or clear prompt history |
|
|
36
|
+
| `dproxy memory` | CRUD for named memory snippets |
|
|
37
|
+
| `dproxy template` | CRUD and execution of YAML prompt templates |
|
|
38
|
+
| `dproxy config` | Get/set configuration |
|
|
39
|
+
|
|
40
|
+
## Context injection
|
|
41
|
+
|
|
42
|
+
Every prompt is enriched with context from multiple sources, in priority order:
|
|
43
|
+
|
|
44
|
+
1. **Day chat log** — today's conversation history
|
|
45
|
+
2. **Workspace bootstrap** — identity/personality files
|
|
46
|
+
3. **Memory snippets** — named markdown snippets (truncated to 4,000 chars)
|
|
47
|
+
4. **Life/PARA context** — semantic knowledge base (truncated to 12,000 chars)
|
|
48
|
+
|
|
49
|
+
## Key flags
|
|
50
|
+
|
|
51
|
+
```
|
|
52
|
+
--no-memory Skip memory injection
|
|
53
|
+
--memory <keys> Inject specific memory keys (comma-separated)
|
|
54
|
+
--no-life Skip life/PARA context
|
|
55
|
+
--no-history Don't save to history
|
|
56
|
+
--raw Print raw JSON response
|
|
57
|
+
-c, --continue Continue last conversation
|
|
58
|
+
-r, --resume <id> Resume a specific session
|
|
59
|
+
-m, --model <model> Model to use
|
|
60
|
+
--max-turns <n> Max agent turns
|
|
61
|
+
--max-budget-usd <n> Max budget in USD
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Data storage
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
~/.dproxy/
|
|
68
|
+
├── config.json # App configuration
|
|
69
|
+
├── history.jsonl # Prompt history
|
|
70
|
+
├── current-session.json # Active session state
|
|
71
|
+
├── memory/ # Named memory snippets (.md)
|
|
72
|
+
└── templates/ # Prompt templates (.yaml)
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Override with `DPROXY_DATA_DIR` env var.
|
|
76
|
+
|
|
77
|
+
## License
|
|
78
|
+
|
|
79
|
+
[MIT](../../LICENSE)
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/index.ts
|
|
4
|
-
import chalk7 from "chalk";
|
|
5
4
|
import { Command as Command7 } from "commander";
|
|
5
|
+
import pc7 from "picocolors";
|
|
6
6
|
|
|
7
7
|
// src/commands/ask.ts
|
|
8
|
-
import chalk from "chalk";
|
|
9
8
|
import { Command } from "commander";
|
|
9
|
+
import pc from "picocolors";
|
|
10
10
|
|
|
11
11
|
// src/claude.ts
|
|
12
12
|
import { spawn } from "child_process";
|
|
@@ -754,7 +754,7 @@ function createAskCommand() {
|
|
|
754
754
|
try {
|
|
755
755
|
await runAsk(promptParts, opts);
|
|
756
756
|
} catch (err) {
|
|
757
|
-
console.error(
|
|
757
|
+
console.error(pc.red(err.message));
|
|
758
758
|
process.exit(1);
|
|
759
759
|
}
|
|
760
760
|
});
|
|
@@ -764,7 +764,7 @@ async function runAsk(promptParts, opts) {
|
|
|
764
764
|
const stdinContent = await readStdin();
|
|
765
765
|
const promptText = promptParts.join(" ");
|
|
766
766
|
if (!promptText && !stdinContent) {
|
|
767
|
-
console.error(
|
|
767
|
+
console.error(pc.red('No prompt provided. Usage: dproxy ask "your question"'));
|
|
768
768
|
process.exit(1);
|
|
769
769
|
}
|
|
770
770
|
let fullPrompt = promptText;
|
|
@@ -856,8 +856,8 @@ ${stdinContent}` : stdinContent;
|
|
|
856
856
|
import { readFile as readFile8, writeFile as writeFile3 } from "fs/promises";
|
|
857
857
|
import { join as join8 } from "path";
|
|
858
858
|
import { createInterface } from "readline";
|
|
859
|
-
import chalk2 from "chalk";
|
|
860
859
|
import { Command as Command2 } from "commander";
|
|
860
|
+
import pc2 from "picocolors";
|
|
861
861
|
var SESSION_FILE = "current-session.json";
|
|
862
862
|
async function loadSession() {
|
|
863
863
|
try {
|
|
@@ -880,7 +880,7 @@ function createChatCommand() {
|
|
|
880
880
|
try {
|
|
881
881
|
await runChat(opts);
|
|
882
882
|
} catch (err) {
|
|
883
|
-
console.error(
|
|
883
|
+
console.error(pc2.red(err.message));
|
|
884
884
|
process.exit(1);
|
|
885
885
|
}
|
|
886
886
|
});
|
|
@@ -890,14 +890,14 @@ async function runChat(opts) {
|
|
|
890
890
|
let sessionId;
|
|
891
891
|
if (opts.resume) {
|
|
892
892
|
sessionId = opts.resume;
|
|
893
|
-
console.log(
|
|
893
|
+
console.log(pc2.dim(`Resuming session: ${sessionId}`));
|
|
894
894
|
} else if (opts.continue) {
|
|
895
895
|
const prev = await loadSession();
|
|
896
896
|
if (prev) {
|
|
897
897
|
sessionId = prev.sessionId;
|
|
898
|
-
console.log(
|
|
898
|
+
console.log(pc2.dim(`Continuing session: ${sessionId}`));
|
|
899
899
|
} else {
|
|
900
|
-
console.log(
|
|
900
|
+
console.log(pc2.dim("No previous session found. Starting new chat."));
|
|
901
901
|
}
|
|
902
902
|
}
|
|
903
903
|
const appendSystemPrompt = await buildSystemPromptContext(
|
|
@@ -909,12 +909,12 @@ async function runChat(opts) {
|
|
|
909
909
|
},
|
|
910
910
|
config
|
|
911
911
|
) || void 0;
|
|
912
|
-
console.log(
|
|
913
|
-
console.log(
|
|
912
|
+
console.log(pc2.bold(pc2.blue("Claude Chat")));
|
|
913
|
+
console.log(pc2.dim('Type "exit" or Ctrl+C to quit.\n'));
|
|
914
914
|
const rl = createInterface({
|
|
915
915
|
input: process.stdin,
|
|
916
916
|
output: process.stdout,
|
|
917
|
-
prompt:
|
|
917
|
+
prompt: pc2.green("you > ")
|
|
918
918
|
});
|
|
919
919
|
rl.prompt();
|
|
920
920
|
rl.on("line", async (line) => {
|
|
@@ -924,13 +924,13 @@ async function runChat(opts) {
|
|
|
924
924
|
return;
|
|
925
925
|
}
|
|
926
926
|
if (input === "exit" || input === "quit") {
|
|
927
|
-
console.log(
|
|
927
|
+
console.log(pc2.dim("Bye!"));
|
|
928
928
|
rl.close();
|
|
929
929
|
return;
|
|
930
930
|
}
|
|
931
931
|
rl.pause();
|
|
932
932
|
try {
|
|
933
|
-
process.stdout.write(
|
|
933
|
+
process.stdout.write(pc2.dim("thinking...\r"));
|
|
934
934
|
const result = await execClaude({
|
|
935
935
|
prompt: input,
|
|
936
936
|
model: opts.model ?? config.defaults.model,
|
|
@@ -939,7 +939,7 @@ async function runChat(opts) {
|
|
|
939
939
|
resumeSessionId: sessionId
|
|
940
940
|
});
|
|
941
941
|
process.stdout.write("\r" + " ".repeat(20) + "\r");
|
|
942
|
-
console.log(
|
|
942
|
+
console.log(pc2.cyan("claude > ") + result.result);
|
|
943
943
|
console.log();
|
|
944
944
|
if (!sessionId && result.sessionId) {
|
|
945
945
|
sessionId = result.sessionId;
|
|
@@ -958,7 +958,7 @@ async function runChat(opts) {
|
|
|
958
958
|
});
|
|
959
959
|
void addChatLog(input, result.result);
|
|
960
960
|
} catch (err) {
|
|
961
|
-
console.error(
|
|
961
|
+
console.error(pc2.red(err.message));
|
|
962
962
|
}
|
|
963
963
|
rl.resume();
|
|
964
964
|
rl.prompt();
|
|
@@ -969,18 +969,18 @@ async function runChat(opts) {
|
|
|
969
969
|
}
|
|
970
970
|
|
|
971
971
|
// src/commands/history.ts
|
|
972
|
-
import chalk3 from "chalk";
|
|
973
972
|
import { Command as Command3 } from "commander";
|
|
973
|
+
import pc3 from "picocolors";
|
|
974
974
|
function printEntryList(entries, showCost = true) {
|
|
975
975
|
if (entries.length === 0) {
|
|
976
|
-
console.log(
|
|
976
|
+
console.log(pc3.dim("No history entries."));
|
|
977
977
|
return;
|
|
978
978
|
}
|
|
979
979
|
for (const e of entries) {
|
|
980
980
|
const date = new Date(e.timestamp).toLocaleString();
|
|
981
981
|
const prompt = e.prompt.length > 60 ? e.prompt.slice(0, 60) + "\u2026" : e.prompt;
|
|
982
|
-
const cost = showCost && e.costUsd ?
|
|
983
|
-
console.log(`${
|
|
982
|
+
const cost = showCost && e.costUsd ? pc3.dim(`$${e.costUsd.toFixed(4)}`) : "";
|
|
983
|
+
console.log(`${pc3.dim(e.id.slice(0, 8))} ${pc3.blue(date)} ${prompt} ${cost}`);
|
|
984
984
|
}
|
|
985
985
|
}
|
|
986
986
|
function createHistoryCommand() {
|
|
@@ -992,17 +992,17 @@ function createHistoryCommand() {
|
|
|
992
992
|
cmd.command("show <id>").description("Show a specific history entry").action(async (id) => {
|
|
993
993
|
const entry = await getHistoryEntry(id);
|
|
994
994
|
if (!entry) {
|
|
995
|
-
console.error(
|
|
995
|
+
console.error(pc3.red(`Entry not found: ${id}`));
|
|
996
996
|
process.exit(1);
|
|
997
997
|
}
|
|
998
|
-
console.log(
|
|
998
|
+
console.log(pc3.bold("Prompt:"));
|
|
999
999
|
console.log(entry.prompt);
|
|
1000
1000
|
console.log();
|
|
1001
|
-
console.log(
|
|
1001
|
+
console.log(pc3.bold("Response:"));
|
|
1002
1002
|
console.log(entry.result);
|
|
1003
1003
|
console.log();
|
|
1004
1004
|
console.log(
|
|
1005
|
-
|
|
1005
|
+
pc3.dim(
|
|
1006
1006
|
`Session: ${entry.sessionId || "n/a"} | Cost: $${entry.costUsd.toFixed(4)} | Duration: ${entry.durationMs}ms | ${entry.timestamp}`
|
|
1007
1007
|
)
|
|
1008
1008
|
);
|
|
@@ -1013,7 +1013,7 @@ function createHistoryCommand() {
|
|
|
1013
1013
|
});
|
|
1014
1014
|
cmd.command("clear").description("Clear history").option("--before <date>", "Clear entries before this date").action(async (opts) => {
|
|
1015
1015
|
const removed = await clearHistory(opts.before);
|
|
1016
|
-
console.log(
|
|
1016
|
+
console.log(pc3.green(`Cleared ${removed} entries.`));
|
|
1017
1017
|
});
|
|
1018
1018
|
cmd.action(async () => {
|
|
1019
1019
|
const entries = await listHistory(20);
|
|
@@ -1024,10 +1024,10 @@ function createHistoryCommand() {
|
|
|
1024
1024
|
|
|
1025
1025
|
// src/commands/init.ts
|
|
1026
1026
|
import { createInterface as createInterface2 } from "readline";
|
|
1027
|
-
import chalk4 from "chalk";
|
|
1028
1027
|
import { Command as Command4 } from "commander";
|
|
1028
|
+
import pc4 from "picocolors";
|
|
1029
1029
|
function ask(rl, question, def = "") {
|
|
1030
|
-
const suffix = def ?
|
|
1030
|
+
const suffix = def ? pc4.dim(` (${def})`) : "";
|
|
1031
1031
|
return new Promise((resolve) => {
|
|
1032
1032
|
rl.question(`${question}${suffix}: `, (answer) => {
|
|
1033
1033
|
resolve(answer.trim() || def);
|
|
@@ -1037,7 +1037,7 @@ function ask(rl, question, def = "") {
|
|
|
1037
1037
|
function askBool(rl, question, def = false) {
|
|
1038
1038
|
const hint = def ? "Y/n" : "y/N";
|
|
1039
1039
|
return new Promise((resolve) => {
|
|
1040
|
-
rl.question(`${question} ${
|
|
1040
|
+
rl.question(`${question} ${pc4.dim(`[${hint}]`)}: `, (answer) => {
|
|
1041
1041
|
const a = answer.trim().toLowerCase();
|
|
1042
1042
|
if (!a) return resolve(def);
|
|
1043
1043
|
resolve(a === "y" || a === "yes");
|
|
@@ -1049,7 +1049,7 @@ function createInitCommand() {
|
|
|
1049
1049
|
try {
|
|
1050
1050
|
await runInit();
|
|
1051
1051
|
} catch (err) {
|
|
1052
|
-
console.error(
|
|
1052
|
+
console.error(pc4.red(err.message));
|
|
1053
1053
|
process.exit(1);
|
|
1054
1054
|
}
|
|
1055
1055
|
});
|
|
@@ -1057,8 +1057,8 @@ function createInitCommand() {
|
|
|
1057
1057
|
async function runInit() {
|
|
1058
1058
|
const config = await loadConfig();
|
|
1059
1059
|
console.log();
|
|
1060
|
-
console.log(
|
|
1061
|
-
console.log(
|
|
1060
|
+
console.log(pc4.bold(pc4.blue("dproxy \u2014 Setup")));
|
|
1061
|
+
console.log(pc4.dim("Configure your environment. Press Enter to accept defaults.\n"));
|
|
1062
1062
|
const rl = createInterface2({
|
|
1063
1063
|
input: process.stdin,
|
|
1064
1064
|
output: process.stdout
|
|
@@ -1077,8 +1077,8 @@ async function runInit() {
|
|
|
1077
1077
|
config.claude.skipPermissions
|
|
1078
1078
|
);
|
|
1079
1079
|
console.log();
|
|
1080
|
-
console.log(
|
|
1081
|
-
console.log(
|
|
1080
|
+
console.log(pc4.bold("Optional integrations"));
|
|
1081
|
+
console.log(pc4.dim("These inject extra context into every prompt.\n"));
|
|
1082
1082
|
const enableWorkspace = await askBool(
|
|
1083
1083
|
rl,
|
|
1084
1084
|
"Enable workspace context (IDENTITY.md, SOUL.md, USER.md, MEMORY.md)?",
|
|
@@ -1103,8 +1103,8 @@ async function runInit() {
|
|
|
1103
1103
|
config.initialized = true;
|
|
1104
1104
|
await saveConfig(config);
|
|
1105
1105
|
console.log();
|
|
1106
|
-
console.log(
|
|
1107
|
-
console.log(
|
|
1106
|
+
console.log(pc4.green("Configuration saved to ") + pc4.dim(getDataDir() + "/config.json"));
|
|
1107
|
+
console.log(pc4.green("You're ready to go! Try: ") + pc4.bold('dproxy "hello"'));
|
|
1108
1108
|
console.log();
|
|
1109
1109
|
} finally {
|
|
1110
1110
|
rl.close();
|
|
@@ -1114,21 +1114,21 @@ async function requireInit() {
|
|
|
1114
1114
|
const config = await loadConfig();
|
|
1115
1115
|
if (config.initialized) return;
|
|
1116
1116
|
console.error(
|
|
1117
|
-
|
|
1117
|
+
pc4.yellow("dproxy is not configured yet. Run ") + pc4.bold("dproxy init") + pc4.yellow(" to set up your environment.")
|
|
1118
1118
|
);
|
|
1119
1119
|
process.exit(1);
|
|
1120
1120
|
}
|
|
1121
1121
|
|
|
1122
1122
|
// src/commands/memory.ts
|
|
1123
|
-
import chalk5 from "chalk";
|
|
1124
1123
|
import { Command as Command5 } from "commander";
|
|
1124
|
+
import pc5 from "picocolors";
|
|
1125
1125
|
function printKeyList(keys) {
|
|
1126
1126
|
if (keys.length === 0) {
|
|
1127
|
-
console.log(
|
|
1127
|
+
console.log(pc5.dim("No memory entries."));
|
|
1128
1128
|
return;
|
|
1129
1129
|
}
|
|
1130
1130
|
for (const key of keys) {
|
|
1131
|
-
console.log(
|
|
1131
|
+
console.log(pc5.blue(key));
|
|
1132
1132
|
}
|
|
1133
1133
|
}
|
|
1134
1134
|
function createMemoryCommand() {
|
|
@@ -1136,12 +1136,12 @@ function createMemoryCommand() {
|
|
|
1136
1136
|
cmd.command("set <key> <value...>").description("Set a memory entry").action(async (key, valueParts) => {
|
|
1137
1137
|
const value = valueParts.join(" ");
|
|
1138
1138
|
await setMemory(key, value);
|
|
1139
|
-
console.log(
|
|
1139
|
+
console.log(pc5.green(`Memory "${key}" saved.`));
|
|
1140
1140
|
});
|
|
1141
1141
|
cmd.command("get <key>").description("Get a memory entry").action(async (key) => {
|
|
1142
1142
|
const value = await getMemory(key);
|
|
1143
1143
|
if (value === null) {
|
|
1144
|
-
console.error(
|
|
1144
|
+
console.error(pc5.red(`Memory "${key}" not found.`));
|
|
1145
1145
|
process.exit(1);
|
|
1146
1146
|
}
|
|
1147
1147
|
console.log(value);
|
|
@@ -1153,20 +1153,20 @@ function createMemoryCommand() {
|
|
|
1153
1153
|
cmd.command("search <query>").description("Search memory entries").action(async (query) => {
|
|
1154
1154
|
const results = await searchMemory(query);
|
|
1155
1155
|
if (results.length === 0) {
|
|
1156
|
-
console.log(
|
|
1156
|
+
console.log(pc5.dim("No matches."));
|
|
1157
1157
|
return;
|
|
1158
1158
|
}
|
|
1159
1159
|
for (const { key, content } of results) {
|
|
1160
1160
|
const preview = content.length > 80 ? content.slice(0, 80) + "\u2026" : content;
|
|
1161
|
-
console.log(`${
|
|
1161
|
+
console.log(`${pc5.blue(key)}: ${preview}`);
|
|
1162
1162
|
}
|
|
1163
1163
|
});
|
|
1164
1164
|
cmd.command("delete <key>").description("Delete a memory entry").action(async (key) => {
|
|
1165
1165
|
const deleted = await deleteMemory(key);
|
|
1166
1166
|
if (deleted) {
|
|
1167
|
-
console.log(
|
|
1167
|
+
console.log(pc5.green(`Memory "${key}" deleted.`));
|
|
1168
1168
|
} else {
|
|
1169
|
-
console.error(
|
|
1169
|
+
console.error(pc5.red(`Memory "${key}" not found.`));
|
|
1170
1170
|
}
|
|
1171
1171
|
});
|
|
1172
1172
|
cmd.action(async () => {
|
|
@@ -1178,8 +1178,8 @@ function createMemoryCommand() {
|
|
|
1178
1178
|
|
|
1179
1179
|
// src/commands/template.ts
|
|
1180
1180
|
import { readFile as readFile10 } from "fs/promises";
|
|
1181
|
-
import chalk6 from "chalk";
|
|
1182
1181
|
import { Command as Command6 } from "commander";
|
|
1182
|
+
import pc6 from "picocolors";
|
|
1183
1183
|
import { parse as parse2 } from "yaml";
|
|
1184
1184
|
|
|
1185
1185
|
// src/lib/template-store.ts
|
|
@@ -1246,32 +1246,32 @@ function createTemplateCommand() {
|
|
|
1246
1246
|
cmd.command("list").description("List all templates").action(async () => {
|
|
1247
1247
|
const templates = await listTemplates();
|
|
1248
1248
|
if (templates.length === 0) {
|
|
1249
|
-
console.log(
|
|
1249
|
+
console.log(pc6.dim("No templates. Use 'dproxy template add <name>' to create one."));
|
|
1250
1250
|
return;
|
|
1251
1251
|
}
|
|
1252
1252
|
for (const t of templates) {
|
|
1253
|
-
const desc = t.description ?
|
|
1254
|
-
console.log(`${
|
|
1253
|
+
const desc = t.description ? pc6.dim(` \u2014 ${t.description}`) : "";
|
|
1254
|
+
console.log(`${pc6.blue(t.name)}${desc}`);
|
|
1255
1255
|
}
|
|
1256
1256
|
});
|
|
1257
1257
|
cmd.command("show <name>").description("Show template details").action(async (name) => {
|
|
1258
1258
|
const t = await getTemplate(name);
|
|
1259
1259
|
if (!t) {
|
|
1260
|
-
console.error(
|
|
1260
|
+
console.error(pc6.red(`Template "${name}" not found.`));
|
|
1261
1261
|
process.exit(1);
|
|
1262
1262
|
}
|
|
1263
|
-
console.log(
|
|
1264
|
-
if (t.description) console.log(
|
|
1263
|
+
console.log(pc6.bold(t.name));
|
|
1264
|
+
if (t.description) console.log(pc6.dim(t.description));
|
|
1265
1265
|
console.log();
|
|
1266
|
-
console.log(
|
|
1266
|
+
console.log(pc6.bold("Prompt:"));
|
|
1267
1267
|
console.log(t.prompt);
|
|
1268
1268
|
if (t.variables?.length) {
|
|
1269
1269
|
console.log();
|
|
1270
|
-
console.log(
|
|
1270
|
+
console.log(pc6.bold("Variables:"));
|
|
1271
1271
|
for (const v of t.variables) {
|
|
1272
|
-
const req = v.required ?
|
|
1273
|
-
const def = v.default ?
|
|
1274
|
-
const src = v.source ?
|
|
1272
|
+
const req = v.required ? pc6.red("*") : "";
|
|
1273
|
+
const def = v.default ? pc6.dim(` (default: ${v.default})`) : "";
|
|
1274
|
+
const src = v.source ? pc6.dim(` [${v.source}]`) : "";
|
|
1275
1275
|
console.log(` {{${v.name}}}${req}${def}${src}`);
|
|
1276
1276
|
}
|
|
1277
1277
|
}
|
|
@@ -1289,16 +1289,16 @@ function createTemplateCommand() {
|
|
|
1289
1289
|
prompt: opts.prompt
|
|
1290
1290
|
};
|
|
1291
1291
|
} else {
|
|
1292
|
-
console.error(
|
|
1292
|
+
console.error(pc6.red("Provide --file or --prompt"));
|
|
1293
1293
|
process.exit(1);
|
|
1294
1294
|
}
|
|
1295
1295
|
await saveTemplate(template);
|
|
1296
|
-
console.log(
|
|
1296
|
+
console.log(pc6.green(`Template "${name}" saved.`));
|
|
1297
1297
|
});
|
|
1298
1298
|
cmd.command("run <name>").description("Run a template").option("--var <pairs...>", "Variables as key=value pairs").option("-m, --model <model>", "Model override").option("--raw", "Print raw JSON response").action(async (name, opts) => {
|
|
1299
1299
|
const t = await getTemplate(name);
|
|
1300
1300
|
if (!t) {
|
|
1301
|
-
console.error(
|
|
1301
|
+
console.error(pc6.red(`Template "${name}" not found.`));
|
|
1302
1302
|
process.exit(1);
|
|
1303
1303
|
}
|
|
1304
1304
|
const vars = {};
|
|
@@ -1322,7 +1322,7 @@ function createTemplateCommand() {
|
|
|
1322
1322
|
vars[v.name] = v.default;
|
|
1323
1323
|
}
|
|
1324
1324
|
if (v.required && !(v.name in vars)) {
|
|
1325
|
-
console.error(
|
|
1325
|
+
console.error(pc6.red(`Missing required variable: {{${v.name}}}`));
|
|
1326
1326
|
process.exit(1);
|
|
1327
1327
|
}
|
|
1328
1328
|
}
|
|
@@ -1341,9 +1341,9 @@ function createTemplateCommand() {
|
|
|
1341
1341
|
cmd.command("delete <name>").description("Delete a template").action(async (name) => {
|
|
1342
1342
|
const deleted = await deleteTemplate(name);
|
|
1343
1343
|
if (deleted) {
|
|
1344
|
-
console.log(
|
|
1344
|
+
console.log(pc6.green(`Template "${name}" deleted.`));
|
|
1345
1345
|
} else {
|
|
1346
|
-
console.error(
|
|
1346
|
+
console.error(pc6.red(`Template "${name}" not found.`));
|
|
1347
1347
|
}
|
|
1348
1348
|
});
|
|
1349
1349
|
return cmd;
|
|
@@ -1367,12 +1367,12 @@ program.addCommand(guarded(createTemplateCommand()));
|
|
|
1367
1367
|
var configCmd = new Command7("config").description("Manage configuration");
|
|
1368
1368
|
configCmd.command("set <key> <value>").description("Set a config value (e.g., memory.autoInject true)").action(async (key, value) => {
|
|
1369
1369
|
await setConfigValue(key, value);
|
|
1370
|
-
console.log(
|
|
1370
|
+
console.log(pc7.green(`${key} = ${value}`));
|
|
1371
1371
|
});
|
|
1372
1372
|
configCmd.command("get <key>").description("Get a config value").action(async (key) => {
|
|
1373
1373
|
const value = await getConfigValue(key);
|
|
1374
1374
|
if (value === void 0) {
|
|
1375
|
-
console.error(
|
|
1375
|
+
console.error(pc7.red(`Config key "${key}" not found.`));
|
|
1376
1376
|
process.exit(1);
|
|
1377
1377
|
}
|
|
1378
1378
|
console.log(JSON.stringify(value, null, 2));
|
|
@@ -1391,7 +1391,7 @@ program.argument("[prompt...]", "Send a quick prompt (shorthand for 'dproxy ask'
|
|
|
1391
1391
|
try {
|
|
1392
1392
|
await runAsk(promptParts, opts);
|
|
1393
1393
|
} catch (err) {
|
|
1394
|
-
console.error(
|
|
1394
|
+
console.error(pc7.red(err.message));
|
|
1395
1395
|
process.exit(1);
|
|
1396
1396
|
}
|
|
1397
1397
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dtoolkit/dproxy",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Universal adapter for invoking models via local CLIs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"adapter"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"
|
|
35
|
+
"picocolors": "^1.1.1",
|
|
36
36
|
"commander": "^13.0.0",
|
|
37
37
|
"yaml": "^2.7.0",
|
|
38
38
|
"@dtoolkit/core": "0.1.0"
|