devin-engine 0.0.2 → 0.0.4
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 +59 -48
- package/dist/engine.d.ts +3 -0
- package/dist/engine.js +15 -6
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,48 +1,59 @@
|
|
|
1
|
-
# devin-engine
|
|
2
|
-
|
|
3
|
-
The guarded-retry / jailbreak pipeline library for the Devin/Cascade backend — a **class, not a server**. Embed it in-process (plugins) or put it behind a standalone proxy; either way the pipeline is the same code path.
|
|
4
|
-
|
|
5
|
-
Sits on top of [`devin-core`](../devin-core) for the wire protocol, auth and catalog. Ported from `devin_proxy/{pipeline,jailbreak,models}` (Python).
|
|
6
|
-
|
|
7
|
-
## What it does per request
|
|
8
|
-
|
|
9
|
-
1. **Resolve** the client model id (+ `reasoning_effort`) to a wire uid — `swe-2-*`, `swe-2-flash-*`, `swe-2-1-*` lanes; never `*-lightning`.
|
|
10
|
-
2. **Sanitize** history — drop empty assistant turns, excise transport notes and the model's own past refusals so they can't anchor the next turn.
|
|
11
|
-
3. **Inject** the system override (hot-reloaded from `~/.devin-proxy/` or the bundled `prompts/`).
|
|
12
|
-
4. **Frame** retries — a mid-history SYSTEM frame seeded by the request text, escalated to a FORCE variant on the last attempt.
|
|
13
|
-
5. **Guard** the stream — the first N chars are held and scanned against a multilingual refusal pattern; a hit burns the attempt and resamples **invisibly** inside the same downstream stream. `full` mode buffers everything to catch comply-then-pivot.
|
|
14
|
-
6. **Translate** tools — native wire tool-calls (primary) or the `<<TOOL_CALL>>` text protocol (fallback), both parsed back into OpenAI `tool_calls`.
|
|
15
|
-
|
|
16
|
-
## Usage
|
|
17
|
-
|
|
18
|
-
```ts
|
|
19
|
-
import { Engine, OverridePrompt } from "devin-engine"
|
|
20
|
-
|
|
21
|
-
const engine = new Engine(
|
|
22
|
-
{ guardChars: 700, maxRetries: 3, nativeTools: true },
|
|
23
|
-
apiKey, // devin-session-token$... or windsurf_api_key
|
|
24
|
-
new OverridePrompt(), // resolves ~/.devin-proxy/override-compact.txt
|
|
25
|
-
catalog, // optional ModelCatalogEntry[] for allowPaid
|
|
26
|
-
)
|
|
27
|
-
|
|
28
|
-
await engine.run(
|
|
29
|
-
openaiChatRequest,
|
|
30
|
-
(delta) => emit(delta), // { role, content? } / { role, tool_calls } deltas
|
|
31
|
-
(result) => finish(result), // { finish_reason }
|
|
32
|
-
(usage) => tally(usage), // token usage
|
|
33
|
-
)
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
## Pieces (all exported)
|
|
37
|
-
|
|
38
|
-
| Export | Purpose |
|
|
39
|
-
| --- | --- |
|
|
40
|
-
| `Engine` | the guarded-retry pipeline |
|
|
41
|
-
| `RefusalGuard`, `REFUSAL_RE` | RU/EN/ZH/ES/PT/FR/DE refusal detection + head buffer |
|
|
42
|
-
| `FrameRouter`, `pickKind` | category routing → seeded frame pools (`game`/`tech`/`llmjb`/`explain`/`direct`/`general`) |
|
|
43
|
-
| `OverridePrompt`, `resolveSystemFile` | override file resolution + mtime hot-reload |
|
|
44
|
-
| `sanitizeMessages`, `sanitizeHistoryArtifacts` | history hygiene |
|
|
45
|
-
| `renderTools`, `parseToolText`, `parseNativeToolText`, `stripProtocolNoise` | tool protocol both directions |
|
|
46
|
-
| `attachReasoning`, `rememberReasoning` | signed-thinking cache replay |
|
|
47
|
-
| `openaiToWire` | OpenAI messages → `ChatHistoryItem[]` |
|
|
48
|
-
| `resolveModel`, `SWE2_*`/`SWE21_*`/`ALL_TIERS` | model-id + effort → wire uid |
|
|
1
|
+
# devin-engine
|
|
2
|
+
|
|
3
|
+
The guarded-retry / jailbreak pipeline library for the Devin/Cascade backend — a **class, not a server**. Embed it in-process (plugins) or put it behind a standalone proxy; either way the pipeline is the same code path.
|
|
4
|
+
|
|
5
|
+
Sits on top of [`devin-core`](../devin-core) for the wire protocol, auth and catalog. Ported from `devin_proxy/{pipeline,jailbreak,models}` (Python).
|
|
6
|
+
|
|
7
|
+
## What it does per request
|
|
8
|
+
|
|
9
|
+
1. **Resolve** the client model id (+ `reasoning_effort`) to a wire uid — `swe-2-*`, `swe-2-flash-*`, `swe-2-1-*` lanes; never `*-lightning`.
|
|
10
|
+
2. **Sanitize** history — drop empty assistant turns, excise transport notes and the model's own past refusals so they can't anchor the next turn.
|
|
11
|
+
3. **Inject** the system override (hot-reloaded from `~/.devin-proxy/` or the bundled `prompts/`).
|
|
12
|
+
4. **Frame** retries — a mid-history SYSTEM frame seeded by the request text, escalated to a FORCE variant on the last attempt.
|
|
13
|
+
5. **Guard** the stream — the first N chars are held and scanned against a multilingual refusal pattern; a hit burns the attempt and resamples **invisibly** inside the same downstream stream. `full` mode buffers everything to catch comply-then-pivot.
|
|
14
|
+
6. **Translate** tools — native wire tool-calls (primary) or the `<<TOOL_CALL>>` text protocol (fallback), both parsed back into OpenAI `tool_calls`.
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import { Engine, OverridePrompt } from "devin-engine"
|
|
20
|
+
|
|
21
|
+
const engine = new Engine(
|
|
22
|
+
{ guardChars: 700, maxRetries: 3, nativeTools: true },
|
|
23
|
+
apiKey, // devin-session-token$... or windsurf_api_key
|
|
24
|
+
new OverridePrompt(), // resolves ~/.devin-proxy/override-compact.txt
|
|
25
|
+
catalog, // optional ModelCatalogEntry[] for allowPaid
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
await engine.run(
|
|
29
|
+
openaiChatRequest,
|
|
30
|
+
(delta) => emit(delta), // { role, content? } / { role, tool_calls } deltas
|
|
31
|
+
(result) => finish(result), // { finish_reason }
|
|
32
|
+
(usage) => tally(usage), // token usage
|
|
33
|
+
)
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Pieces (all exported)
|
|
37
|
+
|
|
38
|
+
| Export | Purpose |
|
|
39
|
+
| --- | --- |
|
|
40
|
+
| `Engine` | the guarded-retry pipeline |
|
|
41
|
+
| `RefusalGuard`, `REFUSAL_RE` | RU/EN/ZH/ES/PT/FR/DE refusal detection + head buffer |
|
|
42
|
+
| `FrameRouter`, `pickKind` | category routing → seeded frame pools (`game`/`tech`/`llmjb`/`explain`/`direct`/`general`) |
|
|
43
|
+
| `OverridePrompt`, `resolveSystemFile` | override file resolution + mtime hot-reload |
|
|
44
|
+
| `sanitizeMessages`, `sanitizeHistoryArtifacts` | history hygiene |
|
|
45
|
+
| `renderTools`, `parseToolText`, `parseNativeToolText`, `stripProtocolNoise` | tool protocol both directions |
|
|
46
|
+
| `attachReasoning`, `rememberReasoning` | signed-thinking cache replay |
|
|
47
|
+
| `openaiToWire` | OpenAI messages → `ChatHistoryItem[]` |
|
|
48
|
+
| `resolveModel`, `SWE2_*`/`SWE21_*`/`ALL_TIERS` | model-id + effort → wire uid |
|
|
49
|
+
|
|
50
|
+
## Ecosystem
|
|
51
|
+
|
|
52
|
+
| Package | Role |
|
|
53
|
+
| --- | --- |
|
|
54
|
+
| `devin-core` | wire + auth + catalog — this package's only runtime dep |
|
|
55
|
+
| **`devin-engine`** (this) | embeddable guarded-retry pipeline |
|
|
56
|
+
| `devin-proxy` | standalone OpenAI-compatible proxy |
|
|
57
|
+
| `devin-proxy-py` | Python original this port tracks |
|
|
58
|
+
| `opencode-devin` | OpenCode v2 plugin |
|
|
59
|
+
| `claude-devin` | Claude-compatible surface |
|
package/dist/engine.d.ts
CHANGED
|
@@ -10,6 +10,9 @@
|
|
|
10
10
|
import { OverridePrompt } from "./override.js";
|
|
11
11
|
export interface EngineSettings {
|
|
12
12
|
backend?: string;
|
|
13
|
+
/** "normal" = vanilla passthrough (no override, no refusal guard, single
|
|
14
|
+
* attempt). "uncensored" = full pipeline. Default "normal". */
|
|
15
|
+
mode?: "normal" | "uncensored";
|
|
13
16
|
guardChars?: number;
|
|
14
17
|
guardFull?: boolean;
|
|
15
18
|
maxRetries?: number;
|
package/dist/engine.js
CHANGED
|
@@ -230,7 +230,8 @@ export class Engine {
|
|
|
230
230
|
const forceTool = tools.length > 0 && data.tool_choice === "required";
|
|
231
231
|
let toolIdx = 0;
|
|
232
232
|
let toolBlock = toolVariants[0] ?? "";
|
|
233
|
-
const
|
|
233
|
+
const uncensored = (s.mode ?? "normal") === "uncensored";
|
|
234
|
+
const override = uncensored ? this.override.load() : "";
|
|
234
235
|
const lang = this.lang();
|
|
235
236
|
let jsonDirective = "";
|
|
236
237
|
const rf = data.response_format;
|
|
@@ -294,7 +295,9 @@ export class Engine {
|
|
|
294
295
|
const maxTokens = (data.max_tokens ?? data.max_completion_tokens ?? 8192);
|
|
295
296
|
const temperature = (data.temperature ?? 0.4);
|
|
296
297
|
const stop = Array.isArray(data.stop) ? data.stop : data.stop ? [String(data.stop)] : [];
|
|
297
|
-
const devAttempts =
|
|
298
|
+
const devAttempts = uncensored
|
|
299
|
+
? 1 + (s.maxRetries ?? 3) + Math.max(0, toolVariants.length - 1)
|
|
300
|
+
: 1;
|
|
298
301
|
let emptyRetry = false;
|
|
299
302
|
for (let attempt = 0; attempt < devAttempts; attempt++) {
|
|
300
303
|
const final = attempt === devAttempts - 1;
|
|
@@ -426,11 +429,17 @@ export class Engine {
|
|
|
426
429
|
}
|
|
427
430
|
async attempt(opts) {
|
|
428
431
|
const s = this.settings;
|
|
429
|
-
const
|
|
432
|
+
const uncensored = (s.mode ?? "normal") === "uncensored";
|
|
433
|
+
// normal mode: guard is a no-op — everything is "released" from the
|
|
434
|
+
// start so text streams straight through and refusal detection never
|
|
435
|
+
// fires (devAttempts is 1 anyway, so a refusal would be terminal).
|
|
436
|
+
const guard = uncensored
|
|
437
|
+
? new RefusalGuard(s.guardChars ?? 700, s.guardFull ?? false)
|
|
438
|
+
: null;
|
|
430
439
|
let text = "";
|
|
431
440
|
let think = "";
|
|
432
441
|
const meta = {};
|
|
433
|
-
let released =
|
|
442
|
+
let released = !uncensored;
|
|
434
443
|
let nFrames = 0;
|
|
435
444
|
const release = () => {
|
|
436
445
|
const payload = opts.tools.length ? text : stripProtocolNoise(text);
|
|
@@ -467,7 +476,7 @@ export class Engine {
|
|
|
467
476
|
}
|
|
468
477
|
else if (ev.kind === "text") {
|
|
469
478
|
text += ev.text;
|
|
470
|
-
if (!released) {
|
|
479
|
+
if (!released && guard) {
|
|
471
480
|
guard.feed(ev.text);
|
|
472
481
|
if (!opts.final && guard.isRefusal()) {
|
|
473
482
|
return { outcome: "refused", text, think };
|
|
@@ -520,7 +529,7 @@ export class Engine {
|
|
|
520
529
|
text = clean;
|
|
521
530
|
}
|
|
522
531
|
}
|
|
523
|
-
if (guard
|
|
532
|
+
if (guard?.full && !released && !meta.native_calls && guard.finish() && !opts.final) {
|
|
524
533
|
return { outcome: "refused", text, think };
|
|
525
534
|
}
|
|
526
535
|
if (meta.native_calls)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "devin-engine",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Embeddable compliance engine over devin-core — guarded-retry pipeline, system-override injection, refusal guard, sanitize, pruning, model resolution. A class, not a server.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"url": "git+https://github.com/JoShMiQueL/devin-engine.git"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"devin-core": "0.0.
|
|
41
|
+
"devin-core": "0.0.3"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@types/bun": "^1.4.4",
|