@cerebriline/agents 4.100.240

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.
@@ -0,0 +1,21 @@
1
+ /**
2
+ * How one request's output divides between thinking, answer text and tool-call
3
+ * input. See `OutputTokenSplit` for what each method means.
4
+ */
5
+ import type { OutputTokenSplit } from "@cerebriline/shared";
6
+ /** What the stream showed of one request, channel by channel. */
7
+ export interface OutputChannelTally {
8
+ reasoningDeltas: number;
9
+ reasoningChars: number;
10
+ textDeltas: number;
11
+ textChars: number;
12
+ toolInputChars: number;
13
+ }
14
+ export declare function emptyOutputChannelTally(): OutputChannelTally;
15
+ export declare function splitOutputTokens(input: {
16
+ outputTokens: number | undefined;
17
+ /** The provider's own count of reasoning tokens, where it reports one. */
18
+ providerReasoningTokens?: number;
19
+ tally: OutputChannelTally;
20
+ }): OutputTokenSplit | undefined;
21
+ //# sourceMappingURL=output-split.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output-split.d.ts","sourceRoot":"","sources":["../src/output-split.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEtD,iEAAiE;AACjE,MAAM,WAAW,kBAAkB;IAClC,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,MAAM,CAAC;CACvB;AAED,wBAAgB,uBAAuB,IAAI,kBAAkB,CAQ5D;AA2BD,wBAAgB,iBAAiB,CAAC,KAAK,EAAE;IACxC,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,0EAA0E;IAC1E,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,KAAK,EAAE,kBAAkB,CAAC;CAC1B,GAAG,gBAAgB,GAAG,SAAS,CA4C/B"}
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Streaming repetition guard for the model's reasoning channel.
3
+ *
4
+ * A model that collapses into a repetition cycle mid-thought will keep
5
+ * generating until something stops it. Locally that is `think_budget`, which
6
+ * cuts the block at a token budget -- but a provider that does not implement a
7
+ * thinking budget (Ollama Cloud, today) leaves nothing between a degenerate
8
+ * draw and the context window. This is the first client-side enforcement of a
9
+ * thinking limit in this codebase; everywhere else a budget is only ever sent
10
+ * to a provider and inferred back (see extensions/context/capped-thinking.ts).
11
+ *
12
+ * Three signals, all derived from real collapses rather than invented:
13
+ *
14
+ * low-uniqueness a full window of completed lines carrying almost no
15
+ * distinct lines. mann1x/cline#69 (GLM-5.3-Flash) spent its
16
+ * first 60k characters flipping two checklist items between
17
+ * "[ ]" and "[x]", which defeats an exact-period test but is
18
+ * unmistakable by this measure.
19
+ * line-cycle the same 1..N lines repeating with an exact period.
20
+ * phrase-cycle no newlines at all -- one fragment repeating inside a
21
+ * single unbroken line ("and I'll do it, and I'll do it...").
22
+ *
23
+ * Length is never the signal. Healthy agentic reasoning on our own harness runs
24
+ * to 150k-260k characters per turn, and a guard that fired on volume would kill
25
+ * every good turn. Only periodicity trips it.
26
+ *
27
+ * Thresholds were set against real data, not intuition: 1,556 reasoning blocks
28
+ * from 82 recorded v7-coder sessions, plus 196k characters of reasoning from a
29
+ * run that successfully completed its task. The deliberately-omitted signal is
30
+ * the answer-channel oracle (tail distinct-5-gram ratio < 0.30), which fires on
31
+ * 2 of 5 healthy blocks from a successful run -- fine for offline labelling,
32
+ * unusable for a guard that aborts live turns.
33
+ */
34
+ import type { ReasoningLoopDetectionConfig } from "@cerebriline/shared";
35
+ /**
36
+ * The detector's thresholds. Defined in `@cerebriline/shared` so a host can set them
37
+ * through `execution.reasoningLoopDetection` without depending on this package.
38
+ */
39
+ export type ReasoningLoopGuardConfig = ReasoningLoopDetectionConfig;
40
+ export declare const DEFAULT_REASONING_LOOP_GUARD: ReasoningLoopGuardConfig;
41
+ export type ReasoningLoopKind = "low-uniqueness" | "line-cycle" | "phrase-cycle";
42
+ export interface ReasoningLoopVerdict {
43
+ kind: ReasoningLoopKind;
44
+ /** Characters of reasoning seen when the guard tripped. */
45
+ chars: number;
46
+ /** Cycle length in lines, or in characters for a phrase cycle. */
47
+ period?: number;
48
+ cycles?: number;
49
+ distinct?: number;
50
+ /** A short excerpt of the repeating unit, for the message shown to the user. */
51
+ sample: string;
52
+ }
53
+ /**
54
+ * Describes what was detected. Deliberately the diagnosis only, never the
55
+ * consequence -- the caller decides what to do about it, the same rule the
56
+ * tool-call loop detector follows.
57
+ */
58
+ export declare function describeReasoningLoop(v: ReasoningLoopVerdict): string;
59
+ export declare class ReasoningLoopGuard {
60
+ private readonly cfg;
61
+ private chars;
62
+ private lines;
63
+ private pending;
64
+ private verdict;
65
+ constructor(config?: Partial<ReasoningLoopGuardConfig>);
66
+ get tripped(): ReasoningLoopVerdict | null;
67
+ /**
68
+ * Feed one reasoning delta. Returns a verdict the first time the block is
69
+ * judged degenerate, and the same verdict on every call after that, so a
70
+ * caller that keeps streaming does not act on it twice.
71
+ */
72
+ push(delta: string): ReasoningLoopVerdict | null;
73
+ private detectLowUniqueness;
74
+ private detectLineCycle;
75
+ private detectPhraseCycle;
76
+ }
77
+ //# sourceMappingURL=reasoning-loop-guard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reasoning-loop-guard.d.ts","sourceRoot":"","sources":["../src/reasoning-loop-guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,eAAe,CAAC;AAElE;;;GAGG;AACH,MAAM,MAAM,wBAAwB,GAAG,4BAA4B,CAAC;AAEpE,eAAO,MAAM,4BAA4B,EAAE,wBAU1C,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAC1B,gBAAgB,GAChB,YAAY,GACZ,cAAc,CAAC;AAElB,MAAM,WAAW,oBAAoB;IACpC,IAAI,EAAE,iBAAiB,CAAC;IACxB,2DAA2D;IAC3D,KAAK,EAAE,MAAM,CAAC;IACd,kEAAkE;IAClE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gFAAgF;IAChF,MAAM,EAAE,MAAM,CAAC;CACf;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,oBAAoB,GAAG,MAAM,CAWrE;AAED,qBAAa,kBAAkB;IAC9B,OAAO,CAAC,QAAQ,CAAC,GAAG,CAA2B;IAC/C,OAAO,CAAC,KAAK,CAAK;IAClB,OAAO,CAAC,KAAK,CAAgB;IAC7B,OAAO,CAAC,OAAO,CAAM;IACrB,OAAO,CAAC,OAAO,CAAqC;gBAExC,MAAM,GAAE,OAAO,CAAC,wBAAwB,CAAM;IAI1D,IAAI,OAAO,IAAI,oBAAoB,GAAG,IAAI,CAEzC;IAED;;;;OAIG;IACH,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,oBAAoB,GAAG,IAAI;IAwBhD,OAAO,CAAC,mBAAmB;IAY3B,OAAO,CAAC,eAAe;IAgCvB,OAAO,CAAC,iBAAiB;CAuBzB"}
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Verbatim self-repetition inside one completed reasoning block.
3
+ *
4
+ * The streaming guard next door (`reasoning-loop-guard.ts`) catches a channel
5
+ * that has *collapsed* -- two lines flipping for 60k characters, an exact line
6
+ * cycle, a phrase repeating inside one unbroken line. This catches something
7
+ * milder and, on our data, far more common: a model that re-derives the same
8
+ * conclusion in fresh-looking prose, paragraph after paragraph, and keeps
9
+ * calling tools while it does it.
10
+ *
11
+ * Measured on pandorum session 1789026721979_kessj, assistant message 30 --
12
+ * 9,728 characters, 65 paragraphs, 41 distinct, one paragraph appearing seven
13
+ * times ("Actually, I think I found it! ... These should all be fine. Let me
14
+ * look more carefully..."). All three signals of the streaming guard are blind
15
+ * to it: the tightest 60-line window still holds 14 distinct lines against a
16
+ * threshold of 4, the longest run at period <= 6 is 4 cycles against a
17
+ * threshold of 20, and the block is full of newlines so the phrase test does
18
+ * not apply. That turn also emitted a tool call, so every turn-level detector
19
+ * saw a productive turn.
20
+ *
21
+ * WHAT IS COUNTED, AND WHY IT IS NOT SIMPLY "REPEATED TEXT". A model quoting
22
+ * the same source line five times while comparing candidate edits is working.
23
+ * Measured: `zssdm` msg 17 repeats one `dPw(c,x){...}` block five times and
24
+ * `swpvy` msg 284 repeats a `function isOverlapping` body eight times, and
25
+ * both are legitimate. So a paragraph counts only when it carries a sentence.
26
+ * Code may ride along inside it -- the real loops read "I will try to replace
27
+ * line 94 with `...` (Wait, no)" -- but a bare fenced quote is never counted.
28
+ *
29
+ * BOTH SIGNALS ARE REQUIRED. On the labelled set the legitimate blocks reach
30
+ * `frac` 0.21 and `maxrep` 10 on their own, so either threshold alone admits
31
+ * them; together they separate 12 of 12 by hand and 38 of 38 on inspection.
32
+ *
33
+ * IT NUDGES, IT NEVER CUTS. Across 3,229 blocks from 21 model families in the
34
+ * harness logs it fires on 1.2%, and those fires land in runs that ended
35
+ * `broken` 44% of the time -- but also in runs that ended FIXED 14% of the
36
+ * time. Four runs in the sample contained a flagged block and still fixed the
37
+ * task. A guard that aborted the turn would have destroyed all four. Looping
38
+ * for a while and then getting there is a thing these models do.
39
+ */
40
+ import type { ReasoningRepetitionConfig } from "@cerebriline/shared";
41
+ /**
42
+ * The shape lives in `@cerebriline/shared` so a host can set it through
43
+ * `execution.reasoningRepetition` without depending on this package; the
44
+ * thresholds live here, with the measurements that set them.
45
+ */
46
+ export type { ReasoningRepetitionConfig };
47
+ export declare const DEFAULT_REASONING_REPETITION: ReasoningRepetitionConfig;
48
+ export interface RepetitionMeasurement {
49
+ /** Counted (prose-bearing) paragraphs. */
50
+ paragraphs: number;
51
+ /** How many counted paragraphs are duplicates of an earlier one. */
52
+ duplicates: number;
53
+ /** `duplicates / paragraphs`. */
54
+ duplicateFraction: number;
55
+ /** Occurrences of the most-repeated paragraph. */
56
+ maxRepeat: number;
57
+ /** That paragraph, for the message shown to the model. */
58
+ sample: string;
59
+ }
60
+ /**
61
+ * Measure one completed reasoning block, or `undefined` if there is nothing to
62
+ * judge (too short, or no prose in it at all).
63
+ */
64
+ export declare function measureReasoningRepetition(text: string, config?: ReasoningRepetitionConfig): RepetitionMeasurement | undefined;
65
+ /** Whether a measurement crosses both thresholds. */
66
+ export declare function isRepetitionLoop(measurement: RepetitionMeasurement | undefined, config?: ReasoningRepetitionConfig): boolean;
67
+ /**
68
+ * What the model is told.
69
+ *
70
+ * Quoting its own sentence back, because the useful information is *which*
71
+ * thought it is stuck on -- a generic "you are repeating yourself" is one a
72
+ * model agrees with and then repeats itself. It names the count, says the
73
+ * thinking is not on the record for the user, and gives one instruction rather
74
+ * than a list: act, or say what is blocking.
75
+ *
76
+ * And it says outright that the evidence cannot be checked. Reasoning replay is
77
+ * `none` on most local endpoints, so the turn being described is not in the
78
+ * request the model is answering -- it is told it repeated something it cannot
79
+ * see. Measured on a gemma4 run: "The previous turn was interrupted by some
80
+ * system messages/errors about repetition (which I don't see in my thought
81
+ * trace but must address)", followed by a turn spent hunting for the evidence
82
+ * instead of acting on it. A model that distrusts the message spends the nudge
83
+ * on doubt, which is the one thing a rationed nudge cannot afford.
84
+ */
85
+ export declare function describeRepetition(measurement: RepetitionMeasurement): string;
86
+ /**
87
+ * Rationed nudges: the guard may interrupt a cycle, not narrate it.
88
+ *
89
+ * A nudge costs a small model attention, so this refuses far more often than
90
+ * it fires -- once per `cooldownTurns`, `maxNudges` in a run.
91
+ */
92
+ export interface RepetitionNudger {
93
+ /** The nudge for this turn's reasoning, or nothing. */
94
+ inspect(text: string, turn: number): string | undefined;
95
+ /** How many nudges have been spent. */
96
+ readonly spent: number;
97
+ }
98
+ export declare function createRepetitionNudger(config?: ReasoningRepetitionConfig): RepetitionNudger;
99
+ //# sourceMappingURL=reasoning-repetition.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reasoning-repetition.d.ts","sourceRoot":"","sources":["../src/reasoning-repetition.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAEH,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAE/D;;;;GAIG;AACH,YAAY,EAAE,yBAAyB,EAAE,CAAC;AAE1C,eAAO,MAAM,4BAA4B,EAAE,yBAkC1C,CAAC;AAcF,MAAM,WAAW,qBAAqB;IACrC,0CAA0C;IAC1C,UAAU,EAAE,MAAM,CAAC;IACnB,oEAAoE;IACpE,UAAU,EAAE,MAAM,CAAC;IACnB,iCAAiC;IACjC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,kDAAkD;IAClD,SAAS,EAAE,MAAM,CAAC;IAClB,0DAA0D;IAC1D,MAAM,EAAE,MAAM,CAAC;CACf;AAWD;;;GAGG;AACH,wBAAgB,0BAA0B,CACzC,IAAI,EAAE,MAAM,EACZ,MAAM,GAAE,yBAAwD,GAC9D,qBAAqB,GAAG,SAAS,CAqCnC;AAED,qDAAqD;AACrD,wBAAgB,gBAAgB,CAC/B,WAAW,EAAE,qBAAqB,GAAG,SAAS,EAC9C,MAAM,GAAE,yBAAwD,GAC9D,OAAO,CAQT;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,qBAAqB,GAAG,MAAM,CAa7E;AAED;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAChC,uDAAuD;IACvD,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IACxD,uCAAuC;IACvC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACvB;AAED,wBAAgB,sBAAsB,CACrC,MAAM,GAAE,yBAAwD,GAC9D,gBAAgB,CA2ClB"}
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@cerebriline/agents",
3
+ "version": "4.100.240",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "git+https://github.com/mann1x/cline.git",
7
+ "directory": "sdk/packages/agents"
8
+ },
9
+ "main": "dist/index.js",
10
+ "dependencies": {
11
+ "nanoid": "^5.1.7",
12
+ "@cerebriline/llms": "4.100.240",
13
+ "@cerebriline/shared": "4.100.240"
14
+ },
15
+ "exports": {
16
+ ".": {
17
+ "browser": "./dist/index.js",
18
+ "types": "./dist/index.d.ts",
19
+ "import": "./dist/index.js"
20
+ }
21
+ },
22
+ "description": "Browser-safe agent runtime for the next-generation Cerebriline SDK",
23
+ "files": [
24
+ "dist"
25
+ ],
26
+ "keywords": [
27
+ "llm",
28
+ "agents",
29
+ "ai",
30
+ "tool-calling"
31
+ ],
32
+ "license": "Apache-2.0",
33
+ "engines": {
34
+ "node": ">=22"
35
+ },
36
+ "type": "module",
37
+ "types": "dist/index.d.ts",
38
+ "homepage": "https://github.com/mann1x/cline/tree/main/sdk",
39
+ "bugs": {
40
+ "url": "https://github.com/mann1x/cline/issues"
41
+ },
42
+ "publishConfig": {
43
+ "access": "public"
44
+ }
45
+ }