dsh-llm-fallbacks 0.4.2 → 0.4.3

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/state.d.ts CHANGED
@@ -31,6 +31,19 @@ import type { FallbackSwitchReason } from './events.ts';
31
31
  import { CooldownStore, StepFailureSet } from './cooldown.ts';
32
32
  import { RecoveryStore } from './recovery.ts';
33
33
  import type { RecoveryPolicy } from './config.ts';
34
+ /**
35
+ * What a switch's failure was actually about.
36
+ *
37
+ * `'route'` (the default) is every failure the plugin has ever walked: the
38
+ * provider/model itself is unhealthy (auth, quota, rate limit, ...), so the
39
+ * from-route is cooled down and counted as a route failure.
40
+ * `'request'` is a failure of the REQUEST on a healthy route — a
41
+ * `CONTEXT_WINDOW_EXCEEDED` rejection is the request being too big, not the
42
+ * model being down. `commit()` keeps the step-scoped bookkeeping for those
43
+ * but writes no suppression and no recovery failure (see `src/index.ts`
44
+ * `REQUEST_SCOPED_CODES`).
45
+ */
46
+ export type SwitchScope = 'route' | 'request';
34
47
  /** Decision awaiting application at the next `agent/request` boundary (spec §5.1). */
35
48
  export interface PendingSwitch {
36
49
  from: {
@@ -43,6 +56,13 @@ export interface PendingSwitch {
43
56
  };
44
57
  role: string;
45
58
  reason: FallbackSwitchReason;
59
+ /**
60
+ * What the failure was about — absent means `'route'`, the semantics every
61
+ * switch had before request-scoped codes existed (same optional-with-a-
62
+ * documented-default idiom as `FallbacksRole.fallback`). Only the
63
+ * `agent/request-error` listener ever sets `'request'`.
64
+ */
65
+ scope?: SwitchScope;
46
66
  }
47
67
  /**
48
68
  * One plugin-originated subagent switch the host allowlist blocked (plan
@@ -125,12 +125,14 @@ export declare const JSON_FIELD_MAX_DRAFT_BYTES: number;
125
125
  export declare function buildFallbacksTuiSection(): TuiSettingsSection;
126
126
  /**
127
127
  * Register the `fallbacks` section on the optional `tuiSettingsSections`
128
- * service. First-fiber-only (`serviceOwned === true` — mirrors
129
- * `installTuiClient` and the gateway/typert multi-fiber dedupe; the host
130
- * registry throws on a duplicate namespace, so a deduped later fiber must
131
- * never register). The service is optional: a composition without
132
- * `dsh-tui-settings-sections` keeps the plugin working and simply omits the
133
- * TUI settings surface.
128
+ * service. Gated by `serviceOwned` — the optimistic apply-time claim (see
129
+ * `apply()` in src/index.ts) — with a sibling dedupe guard inside the child,
130
+ * mirroring `installTuiClient`: the claim is not a fact, so a fiber applying
131
+ * inside the claim window can race another fiber's registration, and the
132
+ * host registry's duplicate throw must degrade (no-op disposer + debug log)
133
+ * instead of failing the child. Any other error stays loud. The service is
134
+ * optional: a composition without `dsh-tui-settings-sections` keeps the
135
+ * plugin working and simply omits the TUI settings surface.
134
136
  *
135
137
  * The inject child returns the registry disposer so cordis withdraws the
136
138
  * registration when this fiber (or the service) goes away.
package/dist/tui.d.ts CHANGED
@@ -42,11 +42,18 @@ export interface TuiCommandTreeProvider {
42
42
  export declare const FALLBACKS_TUI_ROOT = "fallbacks";
43
43
  /**
44
44
  * Register the `/fallbacks` provider on the optional `tuiCommandTrees`
45
- * service. First-fiber-only (`serviceOwned === true` — mirrors the
46
- * gateway/typert multi-fiber dedupe; the host registry throws on duplicate
47
- * roots, so a deduped later fiber must never register). The service is
48
- * optional: a composition without `dsh-tui-command-trees` keeps the plugin
49
- * working and simply omits the TUI surface.
45
+ * service. Gated by the OPTIMISTIC `serviceOwned` claim taken at apply time
46
+ * (the service itself is provided inside the settings inject child, after
47
+ * apply returns — see `apply()` in src/index.ts), with the sibling dedupe
48
+ * guard inside the child: the claim is not a fact, so a fiber applying
49
+ * inside the claim window registers here and, when it loses the race for
50
+ * the host registry's root, degrades via the `already registered` catch
51
+ * below — only a post-settlement duplicate fiber skips at this gate (its
52
+ * claim INITIALIZED false: the service was already visible when the claim
53
+ * was taken; the child-side catch correction settles strictly after apply()
54
+ * and can never influence this synchronous read). The service is optional:
55
+ * a composition without `dsh-tui-command-trees` keeps the plugin working
56
+ * and simply omits the TUI surface.
50
57
  *
51
58
  * The inject child returns the registry disposer so cordis withdraws the
52
59
  * registration when this fiber (or the service) goes away.
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "dsh",
6
6
  "dsh-plugin"
7
7
  ],
8
- "version": "0.4.2",
8
+ "version": "0.4.3",
9
9
  "type": "module",
10
10
  "main": "./dist/index.js",
11
11
  "types": "./dist/index.d.ts",
@@ -362,7 +362,12 @@ for (const match of injectedCssMatches) {
362
362
  }
363
363
  }
364
364
  }
365
- const classMapMatches = [...bundleText.matchAll(/\b\w+_module_css_default\s*=\s*(\{[\s\S]*?\n\s*\});/g)]
365
+ // The class-map object literal is FLAT (string → string, emitted by
366
+ // cssModuleContents as one JSON.stringify), so the lazy match to the first
367
+ // `};` is exact for both emit shapes the printer produces — multi-entry maps
368
+ // across lines and a single-entry map inline (`{ "badge": "_<8hex>_badge" };`
369
+ // has no newline before its closing brace).
370
+ const classMapMatches = [...bundleText.matchAll(/\b\w+_module_css_default\s*=\s*(\{[\s\S]*?\});/g)]
366
371
  if (classMapMatches.length === 0) {
367
372
  throw new Error('client bundle contract: no inlined css-module class map found — check the dsh-css-modules-inline plugin')
368
373
  }
@@ -79,7 +79,7 @@ export function parseArgs(argv: string[]): { version?: string; autoBump: boolean
79
79
  * version stays in its prerelease line, bumping only the numeric tail.
80
80
  */
81
81
  export function autoBumpPatch(current: string): string {
82
- const m = /^(\d+)\.(\d+)\.(\d+)(?:-(.+))?$/.exec(current)
82
+ const m = current.match(/^(\d+)\.(\d+)\.(\d+)(?:-(.+))?$/)
83
83
  if (!m) throw new Error(`Cannot auto-bump "${current}": not a parseable X.Y.Z[-pre] version`)
84
84
  const [, major, minor, patch, pre] = m
85
85
  if (pre === undefined) return `${major}.${minor}.${Number(patch) + 1}`