@traits-dev/cli 0.3.0 → 0.4.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/dist/traits.js +43 -1
- package/package.json +2 -2
package/dist/traits.js
CHANGED
|
@@ -22,6 +22,8 @@ function printCompileUsage(out = process.stderr) {
|
|
|
22
22
|
" --model <model> Model target (required)",
|
|
23
23
|
" --json Output structured JSON",
|
|
24
24
|
" --strict Treat warnings as compile-blocking",
|
|
25
|
+
" --budget Print estimated token count (chars/4)",
|
|
26
|
+
" --budget-limit <tokens> Warn to stderr if estimate exceeds limit",
|
|
25
27
|
" --explain Include compilation trace output",
|
|
26
28
|
" --context key=value Activate context adaptation (repeatable)",
|
|
27
29
|
" --knowledge-base-dir Directory containing compiler pattern files",
|
|
@@ -52,6 +54,8 @@ function parseCompileArgs(args) {
|
|
|
52
54
|
model: null,
|
|
53
55
|
strict: false,
|
|
54
56
|
json: false,
|
|
57
|
+
budget: false,
|
|
58
|
+
budgetLimit: null,
|
|
55
59
|
explain: false,
|
|
56
60
|
verbose: false,
|
|
57
61
|
noColor: false,
|
|
@@ -70,6 +74,10 @@ function parseCompileArgs(args) {
|
|
|
70
74
|
result.json = true;
|
|
71
75
|
continue;
|
|
72
76
|
}
|
|
77
|
+
if (arg === "--budget") {
|
|
78
|
+
result.budget = true;
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
73
81
|
if (arg === "--explain") {
|
|
74
82
|
result.explain = true;
|
|
75
83
|
continue;
|
|
@@ -82,7 +90,7 @@ function parseCompileArgs(args) {
|
|
|
82
90
|
result.noColor = true;
|
|
83
91
|
continue;
|
|
84
92
|
}
|
|
85
|
-
if (arg === "--model" || arg === "--bundled-profiles-dir" || arg === "--context" || arg === "--knowledge-base-dir") {
|
|
93
|
+
if (arg === "--model" || arg === "--bundled-profiles-dir" || arg === "--context" || arg === "--knowledge-base-dir" || arg === "--budget-limit") {
|
|
86
94
|
const value = args[index + 1];
|
|
87
95
|
if (!value) return { error: `Missing value for "${arg}"` };
|
|
88
96
|
if (arg === "--model") {
|
|
@@ -91,6 +99,12 @@ function parseCompileArgs(args) {
|
|
|
91
99
|
result.bundledProfilesDir = value;
|
|
92
100
|
} else if (arg === "--knowledge-base-dir") {
|
|
93
101
|
result.knowledgeBaseDir = value;
|
|
102
|
+
} else if (arg === "--budget-limit") {
|
|
103
|
+
const parsedBudgetLimit = Number(value);
|
|
104
|
+
if (!Number.isFinite(parsedBudgetLimit) || parsedBudgetLimit <= 0) {
|
|
105
|
+
return { error: `Invalid value for "--budget-limit": "${value}"` };
|
|
106
|
+
}
|
|
107
|
+
result.budgetLimit = Math.round(parsedBudgetLimit);
|
|
94
108
|
} else {
|
|
95
109
|
const parsedContext = parseContextArg(value);
|
|
96
110
|
if ("error" in parsedContext) return { error: parsedContext.error };
|
|
@@ -111,8 +125,14 @@ function parseCompileArgs(args) {
|
|
|
111
125
|
if (!result.model) {
|
|
112
126
|
return { error: 'Missing required option "--model"' };
|
|
113
127
|
}
|
|
128
|
+
if (result.budgetLimit != null) {
|
|
129
|
+
result.budget = true;
|
|
130
|
+
}
|
|
114
131
|
return { value: result };
|
|
115
132
|
}
|
|
133
|
+
function estimateBudgetTokens(text) {
|
|
134
|
+
return Math.ceil(String(text ?? "").length / 4);
|
|
135
|
+
}
|
|
116
136
|
function runCompile(args, io = process) {
|
|
117
137
|
const parsed = parseCompileArgs(args);
|
|
118
138
|
if ("error" in parsed) {
|
|
@@ -156,10 +176,32 @@ function runCompile(args, io = process) {
|
|
|
156
176
|
if (options.json) {
|
|
157
177
|
io.stdout.write(`${JSON.stringify(compiled, null, 2)}
|
|
158
178
|
`);
|
|
179
|
+
if (options.budget) {
|
|
180
|
+
const budgetEstimate = estimateBudgetTokens(compiled.text);
|
|
181
|
+
io.stderr.write(`Estimated token count: ${budgetEstimate}
|
|
182
|
+
`);
|
|
183
|
+
if (options.budgetLimit != null && budgetEstimate > options.budgetLimit) {
|
|
184
|
+
io.stderr.write(
|
|
185
|
+
`Warning: Estimated token count ${budgetEstimate} exceeds budget limit ${options.budgetLimit}
|
|
186
|
+
`
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
159
190
|
return 0;
|
|
160
191
|
}
|
|
161
192
|
io.stdout.write(`${compiled.text}
|
|
162
193
|
`);
|
|
194
|
+
if (options.budget) {
|
|
195
|
+
const budgetEstimate = estimateBudgetTokens(compiled.text);
|
|
196
|
+
io.stderr.write(`Estimated token count: ${budgetEstimate}
|
|
197
|
+
`);
|
|
198
|
+
if (options.budgetLimit != null && budgetEstimate > options.budgetLimit) {
|
|
199
|
+
io.stderr.write(
|
|
200
|
+
`Warning: Estimated token count ${budgetEstimate} exceeds budget limit ${options.budgetLimit}
|
|
201
|
+
`
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
163
205
|
if (options.explain && compiled.trace) {
|
|
164
206
|
io.stdout.write(`
|
|
165
207
|
[TRACE]
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@traits-dev/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "traits.dev command-line interface for voice profile init, validate, compile, eval, and import workflows.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"traits-dev",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"provenance": true
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@traits-dev/core": "^0.
|
|
44
|
+
"@traits-dev/core": "^0.4.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@types/node": "^25.2.3",
|