@hmharness/kernel 0.23.39 → 0.23.41

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/config.js CHANGED
@@ -33,7 +33,17 @@ export async function loadConfig() {
33
33
  const file = join(home, 'config.json');
34
34
  try {
35
35
  const raw = JSON.parse(await readFile(file, 'utf8'));
36
- return applyLocaleOverride({ ...defaultConfig(), ...raw, provider: { ...defaultConfig().provider, ...raw.provider } });
36
+ const merged = { ...defaultConfig(), ...raw, provider: { ...defaultConfig().provider, ...raw.provider } };
37
+ // The legacy top-level `provider` is DERIVED from the routed provider
38
+ // whenever routing resolves. A fossil `provider` block holding a
39
+ // rotated-away API key once made every TUI /evolve and /bench call fail
40
+ // with HTTP 401 while normal (routed) chat kept working - the config as
41
+ // loaded must be self-consistent, not a museum of past keys.
42
+ const chatRoute = merged.routing?.chat ?? merged.routing?.evolve;
43
+ const routed = chatRoute ? merged.providers?.[chatRoute] : undefined;
44
+ if (routed?.baseUrl)
45
+ merged.provider = { ...routed };
46
+ return applyLocaleOverride(merged);
37
47
  }
38
48
  catch {
39
49
  return applyLocaleOverride(defaultConfig());
package/dist/loop.js CHANGED
@@ -124,6 +124,9 @@ export async function runLoop(opts) {
124
124
  }
125
125
  const chatRes = await modelCall(provider, compacted, tools, {
126
126
  onDelta: events?.onDelta,
127
+ // the abort must pierce the in-flight call, not just turn boundaries -
128
+ // a hung provider stream otherwise holds the session busy forever
129
+ ...(opts.signal ? { signal: opts.signal } : {}),
127
130
  });
128
131
  usage.promptTokens += chatRes.usage?.prompt_tokens ?? 0;
129
132
  usage.completionTokens += chatRes.usage?.completion_tokens ?? 0;
@@ -33,6 +33,13 @@ export declare function isProviderAuthError(msg: string): boolean;
33
33
  export declare function parseRetryAfterMs(raw: string | null | undefined, maxMs?: number): number;
34
34
  export interface ChatOptions {
35
35
  timeoutMs?: number;
36
+ /** External cancellation (web /api/interrupt, TUI Esc): pierces the
37
+ * in-flight fetch AND its stream reader. Without this link a hung call -
38
+ * e.g. a keep-alive-only SSE stream that bumps the idle guard forever -
39
+ * ignores the abort and holds the session busy until timeoutMs x retries
40
+ * (the 2026-10-26 stuck-executor field reports). A user abort is never
41
+ * retried: intent outranks the resilience loop. */
42
+ signal?: AbortSignal;
36
43
  /** Streaming callback; presence switches the request to stream:true.
37
44
  * kind 'reset' carries an empty chunk and means: the previous attempt died
38
45
  * mid-stream and is being retried - discard what you streamed for it. */
package/dist/provider.js CHANGED
@@ -77,9 +77,19 @@ export async function chat(cfg, messages, tools, opts = {}) {
77
77
  // and mid-stream socket cuts should NEVER kill a long-running task).
78
78
  const MAX_RETRIES = opts.retry?.attempts ?? 6;
79
79
  const BASE_MS = opts.retry?.baseMs ?? 3000;
80
+ const external = opts.signal;
80
81
  for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
82
+ // user cancellation outranks resilience: never start (or retry) after abort
83
+ if (external?.aborted)
84
+ throw new Error('provider: request aborted (external signal)');
81
85
  const ctrl = new AbortController();
82
86
  const timer = setTimeout(() => ctrl.abort(), opts.timeoutMs ?? cfg.timeoutMs ?? 120_000);
87
+ // the external signal links into this attempt's controller so the abort
88
+ // pierces the in-flight fetch and its stream reader, not just turn
89
+ // boundaries (a hung stream otherwise outlives the idle guard)
90
+ const onExternalAbort = () => ctrl.abort();
91
+ if (external)
92
+ external.addEventListener('abort', onExternalAbort, { once: true });
83
93
  // Did this attempt stream anything to the UI before dying? A mid-stream
84
94
  // cut leaves partial deltas on screen; retrying would duplicate them, so
85
95
  // clients are told to drop the partial block first (DeltaKind 'reset').
@@ -137,6 +147,10 @@ export async function chat(cfg, messages, tools, opts = {}) {
137
147
  }
138
148
  catch (err) {
139
149
  lastError = String(err);
150
+ // the caller cancelled: fail now, never retry (a follow-up attempt
151
+ // would only hang the session again against the user's intent)
152
+ if (external?.aborted)
153
+ throw new Error(`provider: request aborted (external signal): ${lastError.slice(0, 120)}`);
140
154
  // transient (network, timeout, connection reset, mid-stream cut): retry
141
155
  if (TRANSIENT_RE.test(lastError)) {
142
156
  // the attempt already painted partial text: tell clients to drop it so
@@ -150,6 +164,8 @@ export async function chat(cfg, messages, tools, opts = {}) {
150
164
  throw err; // permanent error (bad JSON, logic error): don't retry
151
165
  }
152
166
  finally {
167
+ if (external)
168
+ external.removeEventListener('abort', onExternalAbort);
153
169
  clearTimeout(timer);
154
170
  }
155
171
  }
package/package.json CHANGED
@@ -1,28 +1,28 @@
1
- {
2
- "name": "@hmharness/kernel",
3
- "version": "0.23.39",
4
- "description": "hmharness kernel: tool registry, provider adapters, the agent loop, session log, config. Zero runtime dependencies (Node >=22 native fetch).",
5
- "type": "module",
6
- "main": "dist/index.js",
7
- "exports": {
8
- ".": {
9
- "types": "./dist/index.d.ts",
10
- "default": "./dist/index.js"
11
- }
12
- },
13
- "types": "dist/index.d.ts",
14
- "files": [
15
- "dist"
16
- ],
17
- "engines": {
18
- "node": ">=22"
19
- },
20
- "license": "MIT",
21
- "repository": {
22
- "type": "git",
23
- "url": "git+https://github.com/swsgbl/hmharness.git"
24
- },
25
- "scripts": {
26
- "build": "tsc -p tsconfig.build.json"
27
- }
28
- }
1
+ {
2
+ "name": "@hmharness/kernel",
3
+ "version": "0.23.41",
4
+ "description": "hmharness kernel: tool registry, provider adapters, the agent loop, session log, config. Zero runtime dependencies (Node >=22 native fetch).",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "default": "./dist/index.js"
11
+ }
12
+ },
13
+ "types": "dist/index.d.ts",
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "engines": {
18
+ "node": ">=22"
19
+ },
20
+ "license": "MIT",
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/swsgbl/hmharness.git"
24
+ },
25
+ "scripts": {
26
+ "build": "tsc -p tsconfig.build.json"
27
+ }
28
+ }