getprismo 0.1.57 → 0.1.58
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/lib/prismo-dev/enforce.js +13 -4
- package/package.json +1 -1
|
@@ -13,9 +13,16 @@ module.exports = function createEnforce(deps) {
|
|
|
13
13
|
const MAX_COMMAND_FAILURES = 3;
|
|
14
14
|
const MAX_TRACKED_SESSIONS = 8;
|
|
15
15
|
const DENIAL_LOG_LIMIT = 50;
|
|
16
|
-
//
|
|
17
|
-
//
|
|
16
|
+
// Tokens a denied retry keeps out of context. A repeated quiet command saves
|
|
17
|
+
// little; a repeated noisy one (tests, builds, installs) would have dumped a
|
|
18
|
+
// full round of output, so it saves far more.
|
|
18
19
|
const LOOP_DENY_TOKEN_ESTIMATE = 2000;
|
|
20
|
+
const NOISY_LOOP_TOKEN_ESTIMATE = 12000;
|
|
21
|
+
const NOISY_LOOP_RE = /\b(test|jest|vitest|pytest|build|webpack|vite|tsc|install|lint|eslint|playwright|cypress|coverage)\b/i;
|
|
22
|
+
|
|
23
|
+
function loopTokenEstimate(command) {
|
|
24
|
+
return NOISY_LOOP_RE.test(String(command || "")) ? NOISY_LOOP_TOKEN_ESTIMATE : LOOP_DENY_TOKEN_ESTIMATE;
|
|
25
|
+
}
|
|
19
26
|
|
|
20
27
|
function blockedContextPath(root) {
|
|
21
28
|
return path.join(root, ".prismo", "blocked-context.txt");
|
|
@@ -106,7 +113,7 @@ module.exports = function createEnforce(deps) {
|
|
|
106
113
|
reason,
|
|
107
114
|
failures: payload.failures || 0,
|
|
108
115
|
attempts: payload.attempts || 0,
|
|
109
|
-
estimatedTokensSaved: LOOP_DENY_TOKEN_ESTIMATE,
|
|
116
|
+
estimatedTokensSaved: Number(payload.estimatedTokensSaved) || LOOP_DENY_TOKEN_ESTIMATE,
|
|
110
117
|
sessionId,
|
|
111
118
|
}, ...loopStops].slice(0, DENIAL_LOG_LIMIT);
|
|
112
119
|
writeState(root, state);
|
|
@@ -232,10 +239,12 @@ module.exports = function createEnforce(deps) {
|
|
|
232
239
|
const deniedByFailures = !record.succeeded && record.outcomes > 0 && record.failures >= MAX_COMMAND_FAILURES;
|
|
233
240
|
const deniedByAttempts = record.outcomes === 0 && record.attempts >= MAX_IDENTICAL_COMMANDS;
|
|
234
241
|
if (deniedByFailures || deniedByAttempts) {
|
|
235
|
-
|
|
242
|
+
const loopTokens = loopTokenEstimate(command);
|
|
243
|
+
recordDenial(root, state, "loop", command, loopTokens);
|
|
236
244
|
recordLoopStop(root, state, {
|
|
237
245
|
command,
|
|
238
246
|
sessionId,
|
|
247
|
+
estimatedTokensSaved: loopTokens,
|
|
239
248
|
reason: deniedByFailures ? "repeated-failing-command" : "repeated-identical-command",
|
|
240
249
|
failures: record.failures,
|
|
241
250
|
attempts: record.attempts,
|
package/package.json
CHANGED