@swarmdo/cli 1.4.8 → 1.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.
Files changed (88) hide show
  1. package/README.md +3 -1
  2. package/dist/src/commands/hooks.d.ts.map +1 -1
  3. package/dist/src/commands/hooks.js +26 -24
  4. package/dist/src/commands/hooks.js.map +1 -1
  5. package/dist/src/commands/index.d.ts.map +1 -1
  6. package/dist/src/commands/index.js +4 -0
  7. package/dist/src/commands/index.js.map +1 -1
  8. package/dist/src/commands/integrations.d.ts +14 -0
  9. package/dist/src/commands/integrations.d.ts.map +1 -0
  10. package/dist/src/commands/integrations.js +158 -0
  11. package/dist/src/commands/integrations.js.map +1 -0
  12. package/dist/src/commands/memory.d.ts.map +1 -1
  13. package/dist/src/commands/memory.js +50 -1
  14. package/dist/src/commands/memory.js.map +1 -1
  15. package/dist/src/commands/providers.d.ts.map +1 -1
  16. package/dist/src/commands/providers.js +3 -0
  17. package/dist/src/commands/providers.js.map +1 -1
  18. package/dist/src/commands/release.d.ts +15 -0
  19. package/dist/src/commands/release.d.ts.map +1 -0
  20. package/dist/src/commands/release.js +224 -0
  21. package/dist/src/commands/release.js.map +1 -0
  22. package/dist/src/commands/security.d.ts.map +1 -1
  23. package/dist/src/commands/security.js +14 -0
  24. package/dist/src/commands/security.js.map +1 -1
  25. package/dist/src/commands/transcript.d.ts.map +1 -1
  26. package/dist/src/commands/transcript.js +82 -1
  27. package/dist/src/commands/transcript.js.map +1 -1
  28. package/dist/src/commands/usage.d.ts.map +1 -1
  29. package/dist/src/commands/usage.js +80 -1
  30. package/dist/src/commands/usage.js.map +1 -1
  31. package/dist/src/config-lint/lint.d.ts.map +1 -1
  32. package/dist/src/config-lint/lint.js +11 -1
  33. package/dist/src/config-lint/lint.js.map +1 -1
  34. package/dist/src/init/statusline-generator.js +6 -6
  35. package/dist/src/integrations/integrations.d.ts +54 -0
  36. package/dist/src/integrations/integrations.d.ts.map +1 -0
  37. package/dist/src/integrations/integrations.js +162 -0
  38. package/dist/src/integrations/integrations.js.map +1 -0
  39. package/dist/src/mcp-tools/agent-execute-core.d.ts.map +1 -1
  40. package/dist/src/mcp-tools/agent-execute-core.js +25 -3
  41. package/dist/src/mcp-tools/agent-execute-core.js.map +1 -1
  42. package/dist/src/mcp-tools/agentdb-tools.d.ts.map +1 -1
  43. package/dist/src/mcp-tools/agentdb-tools.js +8 -8
  44. package/dist/src/mcp-tools/agentdb-tools.js.map +1 -1
  45. package/dist/src/memory/graph-edge-writer.d.ts +12 -0
  46. package/dist/src/memory/graph-edge-writer.d.ts.map +1 -1
  47. package/dist/src/memory/graph-edge-writer.js +32 -1
  48. package/dist/src/memory/graph-edge-writer.js.map +1 -1
  49. package/dist/src/memory-vault/watch.d.ts +32 -0
  50. package/dist/src/memory-vault/watch.d.ts.map +1 -0
  51. package/dist/src/memory-vault/watch.js +66 -0
  52. package/dist/src/memory-vault/watch.js.map +1 -0
  53. package/dist/src/providers/openrouter-config.d.ts +91 -0
  54. package/dist/src/providers/openrouter-config.d.ts.map +1 -0
  55. package/dist/src/providers/openrouter-config.js +186 -0
  56. package/dist/src/providers/openrouter-config.js.map +1 -0
  57. package/dist/src/release/release.d.ts +72 -0
  58. package/dist/src/release/release.d.ts.map +1 -0
  59. package/dist/src/release/release.js +86 -0
  60. package/dist/src/release/release.js.map +1 -0
  61. package/dist/src/resilience/backoff.d.ts +23 -0
  62. package/dist/src/resilience/backoff.d.ts.map +1 -0
  63. package/dist/src/resilience/backoff.js +30 -0
  64. package/dist/src/resilience/backoff.js.map +1 -0
  65. package/dist/src/swarmvector/model-router.d.ts.map +1 -1
  66. package/dist/src/swarmvector/model-router.js +14 -0
  67. package/dist/src/swarmvector/model-router.js.map +1 -1
  68. package/dist/src/transcript/search.d.ts +39 -0
  69. package/dist/src/transcript/search.d.ts.map +1 -0
  70. package/dist/src/transcript/search.js +67 -0
  71. package/dist/src/transcript/search.js.map +1 -0
  72. package/dist/src/usage/diff.d.ts +69 -0
  73. package/dist/src/usage/diff.d.ts.map +1 -0
  74. package/dist/src/usage/diff.js +112 -0
  75. package/dist/src/usage/diff.js.map +1 -0
  76. package/dist/tsconfig.tsbuildinfo +1 -1
  77. package/package.json +1 -3
  78. package/plugins/swarmdo-metaharness/scripts/smoke.sh +11 -11
  79. package/plugins/swarmdo-metaharness/scripts/test-mcp-tools.mjs +16 -2
  80. package/vendor/cli-core/dist/src/index.js +1 -1
  81. package/vendor/cli-core/dist/src/index.js.map +1 -1
  82. package/vendor/neural/dist/flash-attention.d.ts +1 -1
  83. package/vendor/neural/dist/flash-attention.js +1 -1
  84. package/vendor/shared/dist/hooks/safety/git-commit.js +1 -1
  85. package/vendor/shared/dist/hooks/safety/git-commit.js.map +1 -1
  86. package/vendor/shared/dist/mcp/transport/http.d.ts.map +1 -1
  87. package/vendor/shared/dist/mcp/transport/http.js +8 -1
  88. package/vendor/shared/dist/mcp/transport/http.js.map +1 -1
@@ -0,0 +1,32 @@
1
+ /**
2
+ * watch.ts — debounced change collection for vault auto-sync (phase 2 of the
3
+ * dual-plane memory strategy: edit notes in Obsidian, they sync back to the
4
+ * vector DB as you save).
5
+ *
6
+ * Editors fire bursts of fs events per save (write + rename + metadata);
7
+ * the collector coalesces them into one flush after a quiet window, filters
8
+ * to real notes (.md, not INDEX.md, not dotfiles), and hands relative paths
9
+ * to the sync callback. Pure timing via an injectable scheduler so tests run
10
+ * on fake clocks.
11
+ */
12
+ export interface Scheduler {
13
+ set(fn: () => void, ms: number): unknown;
14
+ clear(handle: unknown): void;
15
+ }
16
+ /** Should this relative path participate in a sync? */
17
+ export declare function isSyncablePath(relPath: string): boolean;
18
+ export declare class ChangeCollector {
19
+ private readonly flush;
20
+ private readonly quietMs;
21
+ private readonly scheduler;
22
+ private pending;
23
+ private handle;
24
+ constructor(flush: (paths: string[]) => void, quietMs?: number, scheduler?: Scheduler);
25
+ /** Record a change; (re)arms the quiet-window timer. */
26
+ add(relPath: string): void;
27
+ /** Flush immediately (shutdown path). No-op when empty. */
28
+ drain(): void;
29
+ get size(): number;
30
+ private fire;
31
+ }
32
+ //# sourceMappingURL=watch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"watch.d.ts","sourceRoot":"","sources":["../../../src/memory-vault/watch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,MAAM,WAAW,SAAS;IACxB,GAAG,CAAC,EAAE,EAAE,MAAM,IAAI,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC;IACzC,KAAK,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI,CAAC;CAC9B;AAOD,uDAAuD;AACvD,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAMvD;AAED,qBAAa,eAAe;IAKxB,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAN5B,OAAO,CAAC,OAAO,CAAqB;IACpC,OAAO,CAAC,MAAM,CAAiB;gBAGZ,KAAK,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,IAAI,EAChC,OAAO,SAAO,EACd,SAAS,GAAE,SAAyB;IAGvD,wDAAwD;IACxD,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAO1B,2DAA2D;IAC3D,KAAK,IAAI,IAAI;IAMb,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,OAAO,CAAC,IAAI;CAOb"}
@@ -0,0 +1,66 @@
1
+ /**
2
+ * watch.ts — debounced change collection for vault auto-sync (phase 2 of the
3
+ * dual-plane memory strategy: edit notes in Obsidian, they sync back to the
4
+ * vector DB as you save).
5
+ *
6
+ * Editors fire bursts of fs events per save (write + rename + metadata);
7
+ * the collector coalesces them into one flush after a quiet window, filters
8
+ * to real notes (.md, not INDEX.md, not dotfiles), and hands relative paths
9
+ * to the sync callback. Pure timing via an injectable scheduler so tests run
10
+ * on fake clocks.
11
+ */
12
+ const realScheduler = {
13
+ set: (fn, ms) => setTimeout(fn, ms),
14
+ clear: (h) => clearTimeout(h),
15
+ };
16
+ /** Should this relative path participate in a sync? */
17
+ export function isSyncablePath(relPath) {
18
+ const base = relPath.split('/').pop() ?? relPath;
19
+ if (!base.endsWith('.md'))
20
+ return false;
21
+ if (base === 'INDEX.md')
22
+ return false;
23
+ if (relPath.split('/').some((seg) => seg.startsWith('.')))
24
+ return false;
25
+ return true;
26
+ }
27
+ export class ChangeCollector {
28
+ flush;
29
+ quietMs;
30
+ scheduler;
31
+ pending = new Set();
32
+ handle = null;
33
+ constructor(flush, quietMs = 1500, scheduler = realScheduler) {
34
+ this.flush = flush;
35
+ this.quietMs = quietMs;
36
+ this.scheduler = scheduler;
37
+ }
38
+ /** Record a change; (re)arms the quiet-window timer. */
39
+ add(relPath) {
40
+ if (!isSyncablePath(relPath))
41
+ return;
42
+ this.pending.add(relPath);
43
+ if (this.handle !== null)
44
+ this.scheduler.clear(this.handle);
45
+ this.handle = this.scheduler.set(() => this.fire(), this.quietMs);
46
+ }
47
+ /** Flush immediately (shutdown path). No-op when empty. */
48
+ drain() {
49
+ if (this.handle !== null)
50
+ this.scheduler.clear(this.handle);
51
+ this.handle = null;
52
+ this.fire();
53
+ }
54
+ get size() {
55
+ return this.pending.size;
56
+ }
57
+ fire() {
58
+ this.handle = null;
59
+ if (this.pending.size === 0)
60
+ return;
61
+ const batch = [...this.pending].sort();
62
+ this.pending.clear();
63
+ this.flush(batch);
64
+ }
65
+ }
66
+ //# sourceMappingURL=watch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"watch.js","sourceRoot":"","sources":["../../../src/memory-vault/watch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAOH,MAAM,aAAa,GAAc;IAC/B,GAAG,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,UAAU,CAAC,EAAE,EAAE,EAAE,CAAC;IACnC,KAAK,EAAE,CAAC,CAA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AC;IAED,2DAA2D;IAC3D,KAAK;QACH,IAAI,IAAI,CAAC,MAAM,KAAK,IAAI;YAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC5D,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACnB,IAAI,CAAC,IAAI,EAAE,CAAC;IACd,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;IAC3B,CAAC;IAEO,IAAI;QACV,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACnB,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC;YAAE,OAAO;QACpC,MAAM,KAAK,GAAG,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC;QACvC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACrB,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACpB,CAAC;CACF"}
@@ -0,0 +1,91 @@
1
+ /**
2
+ * openrouter-config.ts — configurable OpenRouter model pool for swarms.
3
+ *
4
+ * The execution core has dispatched to OpenRouter since #2042, but only via
5
+ * env vars and a single default slug. This module makes the integration
6
+ * CONFIGURABLE: users declare the OpenRouter models they want their agent
7
+ * swarms to draw from in swarmdo.config.json, each mapped to a routing tier,
8
+ * and the router selects among same-tier candidates by Thompson sampling —
9
+ * the concrete consumer for the ADR-149 per-modelId priors.
10
+ *
11
+ * "openrouter": {
12
+ * "enabled": true,
13
+ * "models": [
14
+ * { "id": "meta-llama/llama-3.3-70b-instruct", "tier": "haiku" },
15
+ * { "id": "deepseek/deepseek-chat", "tier": "sonnet" },
16
+ * { "id": "anthropic/claude-opus-4-5", "tier": "opus" }
17
+ * ],
18
+ * "defaultModel": "anthropic/claude-sonnet-4-6"
19
+ * }
20
+ *
21
+ * Everything here is pure (validation, filtering, sampling with injectable
22
+ * randomness) except loadOpenRouterConfig, a thin fs reader.
23
+ */
24
+ export type RoutingTier = 'haiku' | 'sonnet' | 'opus';
25
+ export interface OpenRouterModelEntry {
26
+ /** OpenRouter slug, e.g. 'meta-llama/llama-3.3-70b-instruct' */
27
+ id: string;
28
+ /** Which routing tier this model can serve. Untiered models are only
29
+ * reachable as defaultModel or by explicit slug. */
30
+ tier?: RoutingTier;
31
+ /** Free-form operator note (why it's in the pool, cost expectations…) */
32
+ note?: string;
33
+ }
34
+ export interface OpenRouterConfig {
35
+ enabled: boolean;
36
+ /** env var holding the key (default OPENROUTER_API_KEY) */
37
+ apiKeyEnv: string;
38
+ baseUrl: string;
39
+ defaultModel?: string;
40
+ models: OpenRouterModelEntry[];
41
+ }
42
+ export interface ParseResult {
43
+ config: OpenRouterConfig;
44
+ /** human-readable reasons for every entry/field that was dropped */
45
+ warnings: string[];
46
+ }
47
+ /** OpenRouter slugs are provider/model paths ('org/name[:variant]'). */
48
+ export declare function isOpenRouterSlug(model: string | undefined | null): boolean;
49
+ /** Validate the raw `openrouter` config section. Tolerant at the boundary:
50
+ * bad entries are dropped with a warning, never thrown. */
51
+ export declare function parseOpenRouterConfig(raw: unknown): ParseResult;
52
+ /** Models eligible to serve a tier. */
53
+ export declare function modelsForTier(cfg: OpenRouterConfig, tier: RoutingTier): OpenRouterModelEntry[];
54
+ export interface BetaPrior {
55
+ alpha: number;
56
+ beta: number;
57
+ }
58
+ export type BetaSampler = (alpha: number, beta: number) => number;
59
+ /** Default Beta sampler via two Gamma(α,1)/Gamma(β,1) draws (Marsaglia-Tsang
60
+ * for shape ≥ 1, boost trick below 1). Deterministic tests inject their own. */
61
+ export declare const defaultBetaSampler: BetaSampler;
62
+ export interface PickInput {
63
+ cfg: OpenRouterConfig;
64
+ tier: RoutingTier;
65
+ /** per-modelId Beta priors (ADR-149 shape) — absent models get uniform Beta(1,1) */
66
+ priors?: Record<string, BetaPrior>;
67
+ sample?: BetaSampler;
68
+ }
69
+ export interface PickResult {
70
+ model: string;
71
+ reason: string;
72
+ candidates: number;
73
+ }
74
+ /** Thompson-sample a concrete OpenRouter model for a tier from the
75
+ * user-configured pool. Returns null when disabled or no tier candidates. */
76
+ export declare function pickOpenRouterModel({ cfg, tier, priors, sample }: PickInput): PickResult | null;
77
+ export interface ResolveInput extends Omit<PickInput, 'tier'> {
78
+ /** caller-supplied model: OpenRouter slug passes through; tier word routes via the pool */
79
+ requested?: string;
80
+ tier?: RoutingTier;
81
+ }
82
+ /** Full precedence for the execution path:
83
+ * explicit slug > tier pick from the configured pool > config defaultModel > null. */
84
+ export declare function resolveOpenRouterModel({ requested, tier, cfg, priors, sample }: ResolveInput): {
85
+ model: string;
86
+ source: string;
87
+ } | null;
88
+ /** Thin reader: swarmdo.config.json's `openrouter` section from cwd (or an
89
+ * ancestor repo root). Absent/broken files yield the disabled default. */
90
+ export declare function loadOpenRouterConfig(cwd?: string): ParseResult;
91
+ //# sourceMappingURL=openrouter-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openrouter-config.d.ts","sourceRoot":"","sources":["../../../src/providers/openrouter-config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAKH,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,CAAC;AAGtD,MAAM,WAAW,oBAAoB;IACnC,gEAAgE;IAChE,EAAE,EAAE,MAAM,CAAC;IACX;wDACoD;IACpD,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,yEAAyE;IACzE,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,OAAO,CAAC;IACjB,2DAA2D;IAC3D,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,oBAAoB,EAAE,CAAC;CAChC;AAED,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,gBAAgB,CAAC;IACzB,oE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F;AACvF,wBAAgB,sBAAsB,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,YAAY,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAUvI;AAED;0EAC0E;AAC1E,wBAAgB,oBAAoB,CAAC,GAAG,GAAE,MAAsB,GAAG,WAAW,CAY7E"}
@@ -0,0 +1,186 @@
1
+ /**
2
+ * openrouter-config.ts — configurable OpenRouter model pool for swarms.
3
+ *
4
+ * The execution core has dispatched to OpenRouter since #2042, but only via
5
+ * env vars and a single default slug. This module makes the integration
6
+ * CONFIGURABLE: users declare the OpenRouter models they want their agent
7
+ * swarms to draw from in swarmdo.config.json, each mapped to a routing tier,
8
+ * and the router selects among same-tier candidates by Thompson sampling —
9
+ * the concrete consumer for the ADR-149 per-modelId priors.
10
+ *
11
+ * "openrouter": {
12
+ * "enabled": true,
13
+ * "models": [
14
+ * { "id": "meta-llama/llama-3.3-70b-instruct", "tier": "haiku" },
15
+ * { "id": "deepseek/deepseek-chat", "tier": "sonnet" },
16
+ * { "id": "anthropic/claude-opus-4-5", "tier": "opus" }
17
+ * ],
18
+ * "defaultModel": "anthropic/claude-sonnet-4-6"
19
+ * }
20
+ *
21
+ * Everything here is pure (validation, filtering, sampling with injectable
22
+ * randomness) except loadOpenRouterConfig, a thin fs reader.
23
+ */
24
+ import * as fs from 'node:fs';
25
+ import * as path from 'node:path';
26
+ const TIERS = ['haiku', 'sonnet', 'opus'];
27
+ const DEFAULTS = {
28
+ enabled: false,
29
+ apiKeyEnv: 'OPENROUTER_API_KEY',
30
+ baseUrl: 'https://openrouter.ai/api',
31
+ models: [],
32
+ };
33
+ /** OpenRouter slugs are provider/model paths ('org/name[:variant]'). */
34
+ export function isOpenRouterSlug(model) {
35
+ return typeof model === 'string' && /^[\w.-]+\/[\w.:-]+$/.test(model);
36
+ }
37
+ /** Validate the raw `openrouter` config section. Tolerant at the boundary:
38
+ * bad entries are dropped with a warning, never thrown. */
39
+ export function parseOpenRouterConfig(raw) {
40
+ const warnings = [];
41
+ if (raw === undefined || raw === null)
42
+ return { config: { ...DEFAULTS }, warnings };
43
+ if (typeof raw !== 'object' || Array.isArray(raw)) {
44
+ return { config: { ...DEFAULTS }, warnings: ['openrouter: expected an object — section ignored'] };
45
+ }
46
+ const o = raw;
47
+ const config = { ...DEFAULTS, models: [] };
48
+ config.enabled = o.enabled === true;
49
+ if (typeof o.apiKeyEnv === 'string' && o.apiKeyEnv.trim())
50
+ config.apiKeyEnv = o.apiKeyEnv.trim();
51
+ if (typeof o.baseUrl === 'string' && /^https?:\/\//.test(o.baseUrl))
52
+ config.baseUrl = o.baseUrl.replace(/\/$/, '');
53
+ else if (o.baseUrl !== undefined)
54
+ warnings.push('openrouter.baseUrl: not an http(s) URL — using default');
55
+ if (typeof o.defaultModel === 'string' && isOpenRouterSlug(o.defaultModel))
56
+ config.defaultModel = o.defaultModel;
57
+ else if (o.defaultModel !== undefined)
58
+ warnings.push(`openrouter.defaultModel: "${String(o.defaultModel)}" is not an OpenRouter slug (org/model) — ignored`);
59
+ const rawModels = Array.isArray(o.models) ? o.models : [];
60
+ if (o.models !== undefined && !Array.isArray(o.models))
61
+ warnings.push('openrouter.models: expected an array — ignored');
62
+ const seen = new Set();
63
+ for (const [i, m] of rawModels.entries()) {
64
+ if (typeof m === 'string') {
65
+ // shorthand: bare slug, no tier
66
+ if (isOpenRouterSlug(m) && !seen.has(m)) {
67
+ config.models.push({ id: m });
68
+ seen.add(m);
69
+ }
70
+ else
71
+ warnings.push(`openrouter.models[${i}]: "${m}" is not a valid slug or is a duplicate — dropped`);
72
+ continue;
73
+ }
74
+ if (!m || typeof m !== 'object') {
75
+ warnings.push(`openrouter.models[${i}]: not an object — dropped`);
76
+ continue;
77
+ }
78
+ const e = m;
79
+ if (typeof e.id !== 'string' || !isOpenRouterSlug(e.id)) {
80
+ warnings.push(`openrouter.models[${i}]: missing/invalid id (want 'org/model' slug) — dropped`);
81
+ continue;
82
+ }
83
+ if (seen.has(e.id)) {
84
+ warnings.push(`openrouter.models[${i}]: duplicate id "${e.id}" — dropped`);
85
+ continue;
86
+ }
87
+ const entry = { id: e.id };
88
+ if (e.tier !== undefined) {
89
+ if (typeof e.tier === 'string' && TIERS.includes(e.tier))
90
+ entry.tier = e.tier;
91
+ else {
92
+ warnings.push(`openrouter.models[${i}]: tier "${String(e.tier)}" not in ${TIERS.join('|')} — entry kept untiered`);
93
+ }
94
+ }
95
+ if (typeof e.note === 'string')
96
+ entry.note = e.note;
97
+ config.models.push(entry);
98
+ seen.add(e.id);
99
+ }
100
+ return { config, warnings };
101
+ }
102
+ /** Models eligible to serve a tier. */
103
+ export function modelsForTier(cfg, tier) {
104
+ return cfg.models.filter((m) => m.tier === tier);
105
+ }
106
+ /** Default Beta sampler via two Gamma(α,1)/Gamma(β,1) draws (Marsaglia-Tsang
107
+ * for shape ≥ 1, boost trick below 1). Deterministic tests inject their own. */
108
+ export const defaultBetaSampler = (alpha, beta) => {
109
+ const gamma = (shape) => {
110
+ if (shape < 1)
111
+ return gamma(shape + 1) * Math.pow(Math.random() || 1e-12, 1 / shape);
112
+ const d = shape - 1 / 3;
113
+ const c = 1 / Math.sqrt(9 * d);
114
+ for (;;) {
115
+ const u1 = Math.random() || 1e-12;
116
+ const u2 = Math.random() || 1e-12;
117
+ const n = Math.sqrt(-2 * Math.log(u1)) * Math.cos(2 * Math.PI * u2);
118
+ const v = Math.pow(1 + c * n, 3);
119
+ if (v <= 0)
120
+ continue;
121
+ if (Math.log(u2) < 0.5 * n * n + d - d * v + d * Math.log(v))
122
+ return d * v;
123
+ }
124
+ };
125
+ const a = gamma(alpha);
126
+ const b = gamma(beta);
127
+ return a / (a + b || 1e-12);
128
+ };
129
+ /** Thompson-sample a concrete OpenRouter model for a tier from the
130
+ * user-configured pool. Returns null when disabled or no tier candidates. */
131
+ export function pickOpenRouterModel({ cfg, tier, priors, sample }) {
132
+ if (!cfg.enabled)
133
+ return null;
134
+ const candidates = modelsForTier(cfg, tier);
135
+ if (candidates.length === 0)
136
+ return null;
137
+ if (candidates.length === 1) {
138
+ return { model: candidates[0].id, reason: `only configured ${tier}-tier model`, candidates: 1 };
139
+ }
140
+ const draw = sample ?? defaultBetaSampler;
141
+ let best = null;
142
+ for (const c of candidates) {
143
+ const p = priors?.[c.id] ?? { alpha: 1, beta: 1 };
144
+ const score = draw(Math.max(p.alpha, 1e-9), Math.max(p.beta, 1e-9));
145
+ if (!best || score > best.score)
146
+ best = { id: c.id, score };
147
+ }
148
+ return {
149
+ model: best.id,
150
+ reason: `Thompson pick among ${candidates.length} configured ${tier}-tier models`,
151
+ candidates: candidates.length,
152
+ };
153
+ }
154
+ /** Full precedence for the execution path:
155
+ * explicit slug > tier pick from the configured pool > config defaultModel > null. */
156
+ export function resolveOpenRouterModel({ requested, tier, cfg, priors, sample }) {
157
+ if (isOpenRouterSlug(requested))
158
+ return { model: requested, source: 'explicit' };
159
+ const effectiveTier = tier ?? (requested && TIERS.includes(requested) ? requested : undefined);
160
+ if (effectiveTier) {
161
+ const picked = pickOpenRouterModel({ cfg, tier: effectiveTier, priors, sample });
162
+ if (picked)
163
+ return { model: picked.model, source: picked.reason };
164
+ }
165
+ if (cfg.enabled && cfg.defaultModel)
166
+ return { model: cfg.defaultModel, source: 'config defaultModel' };
167
+ return null;
168
+ }
169
+ /** Thin reader: swarmdo.config.json's `openrouter` section from cwd (or an
170
+ * ancestor repo root). Absent/broken files yield the disabled default. */
171
+ export function loadOpenRouterConfig(cwd = process.cwd()) {
172
+ for (const dir of [cwd, path.resolve(cwd, '..'), path.resolve(cwd, '../..')]) {
173
+ const p = path.join(dir, 'swarmdo.config.json');
174
+ try {
175
+ if (!fs.existsSync(p))
176
+ continue;
177
+ const parsed = JSON.parse(fs.readFileSync(p, 'utf8'));
178
+ return parseOpenRouterConfig(parsed?.openrouter);
179
+ }
180
+ catch {
181
+ return { config: { ...DEFAULTS }, warnings: [`openrouter: failed to read ${p} — integration disabled`] };
182
+ }
183
+ }
184
+ return { config: { ...DEFAULTS }, warnings: [] };
185
+ }
186
+ //# sourceMappingURL=openrouter-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openrouter-config.js","sourceRoot":"","sources":["../../../src/providers/openrouter-config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAGlC,MAAM,KAAK,GAAsB,CAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;AA2B7D,MAAM,QAAQ,GAAqB;IACjC,OAAO,EAAE,KAAK;IACd,SAAS,EAAE,oBAAoB;IAC/B,OAAO,EAAE,2BAA2B;IACpC,MAAM,EAAE,EAAE;CACX,CAAC;AAEF,wEAAwE;AACxE,MAAM,UAAU,gBAAgB,CAAC,KAAgC;IAC/D,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,qBAAqB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AACxE,CAAC;AAED;2DAC2D;AAC3D,MAAM,UAAU,qBAAqB,CAAC,GAAY;IAChD,MAAM,QAAQ,GAAa,EAAE,CAAC;IAC9B,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,IAAI;QAAE,OAAO,EAAE,MAAM,EAAE,EAAE,GAAG,QAAQ,EAAE,EAAE,QAAQ,EAAE,CAAC;IACpF,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QAClD,OAAO,EAAE,MAAM,EAAE,EAAE,GAAG,QAAQ,EAAE,EAAE,QAAQ,EAAE,CAAC,kDAAkD,CAAC,EAAE,CAAC;IACrG,CAAC;IACD,MAAM,CAAC,GAAG,GAA8B,CAAC;IACzC,MAAM,MAAM,GAAqB,EAAE,G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M,EAAE,EAAE,GAAG,QAAQ,EAAE,EAAE,QAAQ,EAAE,CAAC,8BAA8B,CAAC,yBAAyB,CAAC,EAAE,CAAC;QAC3G,CAAC;IACH,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,EAAE,GAAG,QAAQ,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;AACnD,CAAC"}
@@ -0,0 +1,72 @@
1
+ /**
2
+ * release.ts — plan the whole swarmdo release train as data.
3
+ *
4
+ * The proven flow (first executed by hand for v1.4.8) is nine steps: bump the
5
+ * version trio + lockfile, sync the doc version strings, commit+push, build,
6
+ * stage the self-contained @swarmdo/cli, publish both packages, verify the
7
+ * registry, tag, and cut a GitHub release with `swarmdo changelog` notes.
8
+ * This module turns that into a PURE planner — inputs in, an ordered list of
9
+ * typed steps out — so the plan is unit-testable and the command layer only
10
+ * interprets steps (dry-run prints them; --confirm executes them).
11
+ */
12
+ export interface ReleaseInput {
13
+ /** current version from v3/@swarmdo/cli/package.json (trio source of truth) */
14
+ current: string;
15
+ /** 'patch' | 'minor' | 'major' | explicit 'x.y.z' */
16
+ bump: string;
17
+ /** absolute repo root */
18
+ repoRoot: string;
19
+ /** skip npm publish steps (still bumps/commits/tags) */
20
+ skipPublish?: boolean;
21
+ /** skip the gh release step */
22
+ skipGhRelease?: boolean;
23
+ /** skip the live-site deploy (docs-sync rule says DON'T unless the release truly has zero user-facing surface) */
24
+ skipSite?: boolean;
25
+ }
26
+ export type ReleaseStep = {
27
+ kind: 'bump-json';
28
+ file: string;
29
+ version: string;
30
+ } | {
31
+ kind: 'bump-lock';
32
+ file: string;
33
+ version: string;
34
+ } | {
35
+ kind: 'sync-docs';
36
+ version: string;
37
+ files: string[];
38
+ } | {
39
+ kind: 'exec';
40
+ title: string;
41
+ cmd: string;
42
+ args: string[];
43
+ cwd: string;
44
+ } | {
45
+ kind: 'verify-npm';
46
+ packages: string[];
47
+ version: string;
48
+ } | {
49
+ kind: 'gh-release';
50
+ tag: string;
51
+ notesFrom: string;
52
+ } | {
53
+ kind: 'deploy-site';
54
+ version: string;
55
+ };
56
+ export interface ReleasePlan {
57
+ current: string;
58
+ next: string;
59
+ tag: string;
60
+ steps: ReleaseStep[];
61
+ }
62
+ export declare function parseVersion(v: string): [number, number, number];
63
+ export declare function nextVersion(current: string, bump: string): string;
64
+ /** The version trio + lockfile, relative to the repo root. */
65
+ export declare const TRIO_FILES: string[];
66
+ export declare const LOCK_FILE = "package-lock.json";
67
+ /** Docs whose version strings ride along with every release. */
68
+ export declare const DOC_FILES: string[];
69
+ export declare function planRelease(input: ReleaseInput): ReleasePlan;
70
+ /** One-line human rendering of a step (for the dry-run plan). */
71
+ export declare function renderStep(s: ReleaseStep): string;
72
+ //# sourceMappingURL=release.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"release.d.ts","sourceRoot":"","sources":["../../../src/release/release.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,MAAM,WAAW,YAAY;IAC3B,+EAA+E;IAC/E,OAAO,EAAE,MAAM,CAAC;IAChB,qDAAqD;IACrD,IAAI,EAAE,MAAM,CAAC;IACb,yBAAyB;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,wDAAwD;IACxD,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,+BAA+B;IAC/B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,kHAAkH;IAClH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,MAAM,WAAW,GACnB;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACpD;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACpD;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,EAAE,CAAA;CAAE,GACvD;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GACzE;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,QAAQ,EAAE,MAAM,EAAE,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAC3D;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAGtD;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAE7C,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,WAAW,EAAE,CAAC;CACtB;AAID,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAIhE;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAajE;AAED,8DAA8D;AAC9D,eAAO,MAAM,UAAU,UAItB,CAAC;AACF,eAAO,MAAM,SAAS,sBAAsB,CAAC;AAC7C,gEAAgE;AAChE,eAAO,MAAM,SAAS,UAAmD,CAAC;AAE1E,wBAAgB,WAAW,CAAC,KAAK,EAAE,YAAY,GAAG,WAAW,CAgC5D;AAED,iEAAiE;AACjE,wBAAgB,UAAU,CAAC,CAAC,EAAE,WAAW,GAAG,MAAM,CAUjD"}
@@ -0,0 +1,86 @@
1
+ /**
2
+ * release.ts — plan the whole swarmdo release train as data.
3
+ *
4
+ * The proven flow (first executed by hand for v1.4.8) is nine steps: bump the
5
+ * version trio + lockfile, sync the doc version strings, commit+push, build,
6
+ * stage the self-contained @swarmdo/cli, publish both packages, verify the
7
+ * registry, tag, and cut a GitHub release with `swarmdo changelog` notes.
8
+ * This module turns that into a PURE planner — inputs in, an ordered list of
9
+ * typed steps out — so the plan is unit-testable and the command layer only
10
+ * interprets steps (dry-run prints them; --confirm executes them).
11
+ */
12
+ const SEMVER = /^(\d+)\.(\d+)\.(\d+)$/;
13
+ export function parseVersion(v) {
14
+ const m = SEMVER.exec(v.trim());
15
+ if (!m)
16
+ throw new Error(`not a stable semver version: "${v}" (expected x.y.z)`);
17
+ return [Number(m[1]), Number(m[2]), Number(m[3])];
18
+ }
19
+ export function nextVersion(current, bump) {
20
+ const [maj, min, pat] = parseVersion(current);
21
+ switch (bump) {
22
+ case 'patch': return `${maj}.${min}.${pat + 1}`;
23
+ case 'minor': return `${maj}.${min + 1}.0`;
24
+ case 'major': return `${maj + 1}.0.0`;
25
+ default: {
26
+ const [nmaj, nmin, npat] = parseVersion(bump); // throws on junk
27
+ const cmp = nmaj - maj || nmin - min || npat - pat;
28
+ if (cmp <= 0)
29
+ throw new Error(`explicit version ${bump} must be greater than current ${current}`);
30
+ return bump;
31
+ }
32
+ }
33
+ }
34
+ /** The version trio + lockfile, relative to the repo root. */
35
+ export const TRIO_FILES = [
36
+ 'v3/@swarmdo/cli/package.json',
37
+ 'package.json',
38
+ 'swarmdo/package.json',
39
+ ];
40
+ export const LOCK_FILE = 'package-lock.json';
41
+ /** Docs whose version strings ride along with every release. */
42
+ export const DOC_FILES = ['CLAUDE.md', 'README.md', 'website/index.html'];
43
+ export function planRelease(input) {
44
+ const next = nextVersion(input.current, input.bump);
45
+ const tag = `v${next}`;
46
+ const root = input.repoRoot;
47
+ const cli = `${root}/v3/@swarmdo/cli`;
48
+ const steps = [];
49
+ for (const f of TRIO_FILES)
50
+ steps.push({ kind: 'bump-json', file: f, version: next });
51
+ steps.push({ kind: 'bump-lock', file: LOCK_FILE, version: next });
52
+ steps.push({ kind: 'sync-docs', version: next, files: DOC_FILES });
53
+ steps.push({ kind: 'exec', title: 'commit release', cmd: 'git', args: ['commit', '-am', `release: ${tag}`], cwd: root });
54
+ steps.push({ kind: 'exec', title: 'push main', cmd: 'git', args: ['push', 'origin', 'main'], cwd: root });
55
+ if (!input.skipPublish) {
56
+ steps.push({ kind: 'exec', title: 'build @swarmdo/cli', cmd: 'npm', args: ['run', 'build'], cwd: cli });
57
+ steps.push({ kind: 'exec', title: 'stage standalone cli', cmd: 'node', args: ['scripts/build-standalone.mjs'], cwd: cli });
58
+ // NOTE: publish runs from INSIDE dist-standalone — `npm publish <folder>`
59
+ // from the package dir would trip the intentional prepublishOnly guard
60
+ steps.push({ kind: 'exec', title: 'publish @swarmdo/cli', cmd: 'npm', args: ['publish'], cwd: `${cli}/dist-standalone` });
61
+ steps.push({ kind: 'exec', title: 'publish swarmdo umbrella', cmd: 'npm', args: ['publish'], cwd: root });
62
+ steps.push({ kind: 'verify-npm', packages: ['@swarmdo/cli', 'swarmdo'], version: next });
63
+ }
64
+ steps.push({ kind: 'exec', title: 'tag', cmd: 'git', args: ['tag', tag, 'main'], cwd: root });
65
+ steps.push({ kind: 'exec', title: 'push tag', cmd: 'git', args: ['push', 'origin', tag], cwd: root });
66
+ if (!input.skipGhRelease) {
67
+ steps.push({ kind: 'gh-release', tag, notesFrom: `v${input.current}` });
68
+ }
69
+ if (!input.skipSite) {
70
+ steps.push({ kind: 'deploy-site', version: next });
71
+ }
72
+ return { current: input.current, next, tag, steps };
73
+ }
74
+ /** One-line human rendering of a step (for the dry-run plan). */
75
+ export function renderStep(s) {
76
+ switch (s.kind) {
77
+ case 'bump-json': return `bump ${s.file} → ${s.version}`;
78
+ case 'bump-lock': return `bump ${s.file} (version + packages."") → ${s.version}`;
79
+ case 'sync-docs': return `sync version strings → ${s.version} in ${s.files.join(', ')}`;
80
+ case 'exec': return `${s.title}: ${s.cmd} ${s.args.join(' ')} (${s.cwd})`;
81
+ case 'verify-npm': return `verify npm: ${s.packages.join(', ')} @latest === ${s.version}`;
82
+ case 'gh-release': return `gh release ${s.tag} with \`swarmdo changelog\` notes since ${s.notesFrom}`;
83
+ case 'deploy-site': return `deploy website → SwarmDo/swarmdo.com (copy working copy, push, curl-verify swarmdo.com serves ${s.version})`;
84
+ }
85
+ }
86
+ //# sourceMappingURL=release.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"release.js","sourceRoot":"","sources":["../../../src/release/release.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAmCH,MAAM,MAAM,GAAG,uBAAuB,CAAC;AAEvC,MAAM,UAAU,YAAY,CAAC,CAAS;IACpC,MAAM,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IAChC,IAAI,CAAC,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,oBAAoB,CAAC,CAAC;IAChF,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACpD,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,OAAe,EAAE,IAAY;IACvD,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;IAC9C,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,OAAO,CAAC,CAAC,OAAO,GAAG,GAAG,IAAI,GAAG,IAAI,GAAG,GAAG,CAAC,EAAE,CAAC;QAChD,KAAK,OAAO,CAAC,CAAC,OAAO,GAAG,GAAG,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;QAC3C,KAAK,OAAO,CAAC,CAAC,OAAO,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC;QACtC,OAAO,CAAC,CAAC,CAAC;YACR,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,C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,CAAC,OAAO,QAAQ,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,OAAO,EAAE,CAAC;QACzD,KAAK,WAAW,CAAC,CAAC,OAAO,QAAQ,CAAC,CAAC,IAAI,8BAA8B,CAAC,CAAC,OAAO,EAAE,CAAC;QACjF,KAAK,WAAW,CAAC,CAAC,OAAO,0BAA0B,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACxF,KAAK,MAAM,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,KAAK,MAAM,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,GAAG,CAAC;QAC5E,KAAK,YAAY,CAAC,CAAC,OAAO,eAAe,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,OAAO,EAAE,CAAC;QAC1F,KAAK,YAAY,CAAC,CAAC,OAAO,cAAc,CAAC,CAAC,GAAG,2CAA2C,CAAC,CAAC,SAAS,EAAE,CAAC;QACtG,KAAK,aAAa,CAAC,CAAC,OAAO,iGAAiG,CAAC,CAAC,OAAO,GAAG,CAAC;IAC3I,CAAC;AACH,CAAC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * backoff.ts — exponential backoff with full jitter for retryable provider
3
+ * failures (429 / 5xx / timeouts).
4
+ *
5
+ * The ADR-149 fallback chain retried instantly; a provider-level 429 is
6
+ * usually account-wide, so an immediate re-call burns the attempt. Standard
7
+ * remedy (AWS architecture blog, anthropic SDK internals): exponential base
8
+ * with FULL jitter, capped. Pure — the jitter source is injectable so tests
9
+ * are deterministic.
10
+ */
11
+ export interface BackoffOptions {
12
+ /** first-attempt base delay (default 1000ms) */
13
+ baseMs?: number;
14
+ /** hard cap per delay (default 8000ms) */
15
+ capMs?: number;
16
+ /** jitter source mapping an upper bound to a value in [0, bound); injectable for tests */
17
+ jitter?: (boundMs: number) => number;
18
+ }
19
+ /** Delay before retry `attempt` (0-based): full-jitter exp backoff. */
20
+ export declare function computeBackoffMs(attempt: number, opts?: BackoffOptions): number;
21
+ export declare function isRetryableError(errText: string | null | undefined): boolean;
22
+ export declare function sleep(ms: number): Promise<void>;
23
+ //# sourceMappingURL=backoff.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backoff.d.ts","sourceRoot":"","sources":["../../../src/resilience/backoff.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,MAAM,WAAW,cAAc;IAC7B,gDAAgD;IAChD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,0CAA0C;IAC1C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,0FAA0F;IAC1F,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC;CACtC;AAED,uEAAuE;AACvE,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,cAAmB,GAAG,MAAM,CAMnF;AAQD,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAE5E;AAED,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE/C"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * backoff.ts — exponential backoff with full jitter for retryable provider
3
+ * failures (429 / 5xx / timeouts).
4
+ *
5
+ * The ADR-149 fallback chain retried instantly; a provider-level 429 is
6
+ * usually account-wide, so an immediate re-call burns the attempt. Standard
7
+ * remedy (AWS architecture blog, anthropic SDK internals): exponential base
8
+ * with FULL jitter, capped. Pure — the jitter source is injectable so tests
9
+ * are deterministic.
10
+ */
11
+ /** Delay before retry `attempt` (0-based): full-jitter exp backoff. */
12
+ export function computeBackoffMs(attempt, opts = {}) {
13
+ const base = opts.baseMs ?? 1000;
14
+ const cap = opts.capMs ?? 8000;
15
+ const jitter = opts.jitter ?? ((bound) => Math.random() * bound);
16
+ const bound = Math.min(cap, base * 2 ** Math.max(0, attempt));
17
+ return Math.floor(jitter(bound));
18
+ }
19
+ /** Retryable-failure classifier shared with the fallback chain. */
20
+ // \b only guards the numeric codes ('5031' must not match); the word classes
21
+ // match as substrings because providers emit snake_case ('overloaded_error',
22
+ // 'rate_limited') where \b fails before the underscore
23
+ const RETRYABLE = /\b(429|500|502|503|504)\b|timeout|overloaded|rate.?limit|ECONNRESET|ETIMEDOUT/i;
24
+ export function isRetryableError(errText) {
25
+ return RETRYABLE.test(errText ?? '');
26
+ }
27
+ export function sleep(ms) {
28
+ return new Promise((resolve) => setTimeout(resolve, ms));
29
+ }
30
+ //# sourceMappingURL=backoff.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backoff.js","sourceRoot":"","sources":["../../../src/resilience/backoff.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAWH,uEAAuE;AACvE,MAAM,UAAU,gBAAgB,CAAC,OAAe,EAAE,OAAuB,EAAE;IACzE,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC;IACjC,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC;IAC/B,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC,KAAa,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC;IACzE,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,GAAG,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;IAC9D,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AACnC,CAAC;AAED,mEAAmE;AACnE,6EAA6E;AAC7E,6EAA6E;AAC7E,uDAAuD;AACvD,MAAM,SAAS,GAAG,gFAAgF,CAAC;AAEnG,MAAM,UAAU,gBAAgB,CAAC,OAAkC;IACjE,OAAO,SAAS,CAAC,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC;AACvC,CAAC;AAED,MAAM,UAAU,KAAK,CAAC,EAAU;IAC9B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAC3D,CAAC"}