@hmharness/kernel 0.4.3 → 0.5.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/loop.js +12 -1
- package/package.json +1 -1
package/dist/loop.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* no gate configured means deny (safe default). Between turns the
|
|
8
8
|
* transcript is compacted against the context budget.
|
|
9
9
|
*/
|
|
10
|
-
import { compactMessages, compactWithDigest } from "./context.js";
|
|
10
|
+
import { compactMessages, compactWithDigest, transcriptChars } from "./context.js";
|
|
11
11
|
import { adaptiveContextChars } from "./window.js";
|
|
12
12
|
import { chat } from "./provider.js";
|
|
13
13
|
export async function runLoop(opts) {
|
|
@@ -19,10 +19,21 @@ export async function runLoop(opts) {
|
|
|
19
19
|
let toolUses = 0;
|
|
20
20
|
const usage = { promptTokens: 0, completionTokens: 0 };
|
|
21
21
|
const tools = registry.toOpenAITools();
|
|
22
|
+
let wrapupSignaled = false;
|
|
22
23
|
for (let turn = 1; turn <= maxTurns; turn++) {
|
|
23
24
|
const compacted = opts.summarizeContext
|
|
24
25
|
? await compactWithDigest(working, budget, opts.summarizeContext)
|
|
25
26
|
: compactMessages(working, budget);
|
|
27
|
+
// Budget wrap-up signal: when context usage crosses 80%, inject a
|
|
28
|
+
// single system nudge to wind down instead of hard-cutting mid-thought
|
|
29
|
+
// (Codex's token-budget-context pattern; DeepSeek's 80% pressure trigger).
|
|
30
|
+
if (!wrapupSignaled && transcriptChars(compacted) > budget * 0.8) {
|
|
31
|
+
wrapupSignaled = true;
|
|
32
|
+
working.push({
|
|
33
|
+
role: 'system',
|
|
34
|
+
content: '[context budget] Context is running low. Wrap up the current task: summarize what was accomplished, suggest concrete next steps, and stop starting new sub-tasks.',
|
|
35
|
+
});
|
|
36
|
+
}
|
|
26
37
|
const chatRes = await modelCall(provider, compacted, tools, {
|
|
27
38
|
onDelta: events?.onDelta,
|
|
28
39
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hmharness/kernel",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "hmharness kernel: tool registry, provider adapters, the agent loop, session log, config. Zero runtime dependencies (Node >=22 native fetch).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|