@hmharness/kernel 0.6.1 → 0.6.2

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.d.ts CHANGED
@@ -31,6 +31,10 @@ export declare function runLoop(opts: {
31
31
  messages: ChatMessage[];
32
32
  ctx: ToolContext;
33
33
  maxTurns?: number;
34
+ /** AbortSignal: when fired, the loop stops at the next turn boundary and
35
+ * returns with reason "interrupted". Use for user-initiated cancellation
36
+ * (Esc key, /queue skip, web API interrupt). */
37
+ signal?: AbortSignal;
34
38
  /** Explicit transcript budget override (chars). Default: scales with the
35
39
  * model's context window (window.ts registry / provider.contextWindow). */
36
40
  maxContextChars?: number;
package/dist/loop.js CHANGED
@@ -43,6 +43,10 @@ export async function runLoop(opts) {
43
43
  reason = 'token-valve';
44
44
  break;
45
45
  }
46
+ if (opts.signal?.aborted) {
47
+ reason = 'interrupted';
48
+ break;
49
+ }
46
50
  const compacted = opts.summarizeContext
47
51
  ? await compactWithDigest(working, budget, opts.summarizeContext)
48
52
  : compactMessages(working, budget);
@@ -156,11 +160,13 @@ export async function runLoop(opts) {
156
160
  }
157
161
  // Safety valve or idle detection fired
158
162
  const executedTurns = reason === 'idle' ? turn : turn - 1;
159
- const text = reason === 'idle'
160
- ? `Agent appears stuck: ${maxIdle} consecutive turns with no successful tool calls. The session is preserved — review the transcript, adjust the approach, and send a new message to continue.`
161
- : reason === 'turn-valve'
162
- ? `Turn limit reached (${executedTurns} turns). The session is preserved — send another message to continue.`
163
- : `Token budget limit reached (~${usage.promptTokens + usage.completionTokens} tokens). The session is preserved — send another message to continue.`;
163
+ const text = reason === 'interrupted'
164
+ ? `Task interrupted by user at turn ${turn}. Partial results preserved — the transcript is resumable.`
165
+ : reason === 'idle'
166
+ ? `Agent appears stuck: ${maxIdle} consecutive turns with no successful tool calls. The session is preserved — review the transcript, adjust the approach, and send a new message to continue.`
167
+ : reason === 'turn-valve'
168
+ ? `Turn limit reached (${executedTurns} turns). The session is preserved — send another message to continue.`
169
+ : `Token budget limit reached (~${usage.promptTokens + usage.completionTokens} tokens). The session is preserved — send another message to continue.`;
164
170
  events?.onFinal?.(text, executedTurns);
165
171
  return { text, turns: executedTurns, toolUses, messages: working, usage };
166
172
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hmharness/kernel",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
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",