@claude-flow/cli 3.68.0 → 3.70.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 (64) hide show
  1. package/.claude/helpers/helpers.manifest.json +2 -2
  2. package/.claude/skills/agentdb-advanced/SKILL.md +1 -1
  3. package/.claude/skills/agentdb-learning/SKILL.md +1 -1
  4. package/.claude/skills/agentdb-memory-patterns/SKILL.md +1 -1
  5. package/.claude/skills/agentdb-optimization/SKILL.md +1 -1
  6. package/.claude/skills/agentdb-vector-search/SKILL.md +1 -1
  7. package/.claude/skills/hooks-automation/SKILL.md +1 -1
  8. package/.claude/skills/pair-programming/SKILL.md +1 -1
  9. package/.claude/skills/reasoningbank-agentdb/SKILL.md +1 -1
  10. package/.claude/skills/reasoningbank-intelligence/SKILL.md +1 -1
  11. package/.claude/skills/skill-builder/SKILL.md +1 -1
  12. package/.claude/skills/swarm-orchestration/SKILL.md +1 -1
  13. package/.claude/skills/v3-cli-modernization/SKILL.md +1 -1
  14. package/.claude/skills/v3-core-implementation/SKILL.md +1 -1
  15. package/.claude/skills/v3-ddd-architecture/SKILL.md +1 -1
  16. package/.claude/skills/v3-integration-deep/SKILL.md +1 -1
  17. package/.claude/skills/v3-mcp-optimization/SKILL.md +1 -1
  18. package/.claude/skills/v3-memory-unification/SKILL.md +1 -1
  19. package/.claude/skills/v3-performance-optimization/SKILL.md +1 -1
  20. package/.claude/skills/v3-security-overhaul/SKILL.md +1 -1
  21. package/.claude/skills/v3-swarm-coordination/SKILL.md +1 -1
  22. package/.claude/skills/verification-quality/SKILL.md +1 -1
  23. package/catalog-manifest.json +3 -3
  24. package/dist/src/commands/context-plan.d.ts +4 -0
  25. package/dist/src/commands/context-plan.js +36 -0
  26. package/dist/src/commands/hooks.js +20 -4
  27. package/dist/src/commands/workflow.js +3 -1
  28. package/dist/src/index.d.ts +4 -0
  29. package/dist/src/index.js +3 -0
  30. package/dist/src/mcp-tools/agent-tools.js +31 -14
  31. package/dist/src/mcp-tools/agentdb-episode-tools.d.ts +16 -0
  32. package/dist/src/mcp-tools/agentdb-episode-tools.js +214 -0
  33. package/dist/src/mcp-tools/agentdb-tools.js +2 -0
  34. package/dist/src/mcp-tools/claims-tools.js +7 -3
  35. package/dist/src/mcp-tools/config-tools.js +48 -22
  36. package/dist/src/mcp-tools/coordination-tools.js +5 -2
  37. package/dist/src/mcp-tools/daa-tools.js +12 -5
  38. package/dist/src/mcp-tools/hooks-tools.js +46 -7
  39. package/dist/src/mcp-tools/session-tools.d.ts +10 -0
  40. package/dist/src/mcp-tools/session-tools.js +15 -2
  41. package/dist/src/mcp-tools/workflow-tools.js +9 -4
  42. package/dist/src/memory/episode-crud.d.ts +70 -0
  43. package/dist/src/memory/episode-crud.js +114 -0
  44. package/dist/src/memory/ewc-consolidation.d.ts +7 -0
  45. package/dist/src/memory/ewc-consolidation.js +19 -1
  46. package/dist/src/memory/memory-bridge.d.ts +5 -0
  47. package/dist/src/memory/memory-bridge.js +38 -3
  48. package/dist/src/mods/command-registry/schema.d.ts +6 -6
  49. package/dist/src/services/anthropic-context-adapter.d.ts +81 -0
  50. package/dist/src/services/anthropic-context-adapter.js +257 -0
  51. package/dist/src/services/context-delegation.d.ts +107 -0
  52. package/dist/src/services/context-delegation.js +193 -0
  53. package/node_modules/@claude-flow/codex/dist/cli.js +0 -0
  54. package/node_modules/@claude-flow/plugin-agent-federation/dist/application/policy-engine.d.ts +1 -0
  55. package/node_modules/@claude-flow/plugin-agent-federation/dist/application/policy-engine.d.ts.map +1 -1
  56. package/node_modules/@claude-flow/plugin-agent-federation/dist/application/policy-engine.js +8 -0
  57. package/node_modules/@claude-flow/plugin-agent-federation/dist/application/policy-engine.js.map +1 -1
  58. package/node_modules/@claude-flow/plugin-agent-federation/dist/bin.js +0 -0
  59. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/entities/trust-level.d.ts.map +1 -1
  60. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/entities/trust-level.js +9 -2
  61. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/entities/trust-level.js.map +1 -1
  62. package/node_modules/@claude-flow/security/dist/input-validator.d.ts +6 -6
  63. package/package.json +5 -5
  64. package/.claude/memory.db +0 -0
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Episode get / list / update / delete over agentdb 3.3's ReflexionMemory (ADR-520).
3
+ *
4
+ * Episodes are what session ends and `memory distill` record, and what
5
+ * `agentdb_episode-recall` searches. agentdb 3.3 keeps the id on update and moves the row,
6
+ * embedding, vector entry and keyword index together; this module only validates, bounds
7
+ * what goes back over MCP, and feature-detects older agentdb builds.
8
+ *
9
+ * @module v3/cli/memory/episode-crud
10
+ */
11
+ export declare const EPISODE_CRUD_UNAVAILABLE = "Episode get/list/update/delete needs agentdb >= 3.3.0 with ReflexionMemory available.";
12
+ export interface EpisodeView {
13
+ id: number;
14
+ sessionId: string;
15
+ task: string;
16
+ input?: string;
17
+ output?: string;
18
+ critique?: string;
19
+ reward: number;
20
+ success: boolean;
21
+ latencyMs?: number;
22
+ tokensUsed?: number;
23
+ tags?: string[];
24
+ metadata?: Record<string, unknown>;
25
+ ts?: number;
26
+ }
27
+ export interface EpisodePatch {
28
+ task?: string;
29
+ input?: string | null;
30
+ output?: string | null;
31
+ critique?: string | null;
32
+ reward?: number;
33
+ success?: boolean;
34
+ tags?: string[] | null;
35
+ metadata?: Record<string, unknown> | null;
36
+ }
37
+ export type CrudResult<T> = {
38
+ success: true;
39
+ } & T | {
40
+ success: false;
41
+ error: string;
42
+ };
43
+ /** Strict positive integer id. "12-notes" must never reach a delete as 12. */
44
+ export declare function parseEpisodeId(value: unknown): number | null;
45
+ export declare function bridgeGetEpisode(id: number, dbPath?: string): Promise<CrudResult<{
46
+ episode: EpisodeView | null;
47
+ }> | null>;
48
+ export declare function bridgeListEpisodes(options: {
49
+ sessionId?: string;
50
+ success?: boolean;
51
+ limit?: number;
52
+ offset?: number;
53
+ order?: 'newest' | 'oldest';
54
+ }, dbPath?: string): Promise<CrudResult<{
55
+ episodes: EpisodeView[];
56
+ total: number;
57
+ limit: number;
58
+ offset: number;
59
+ }> | null>;
60
+ export declare function bridgeUpdateEpisode(id: number, patch: EpisodePatch, options?: {
61
+ replaceMetadata?: boolean;
62
+ }, dbPath?: string): Promise<CrudResult<{
63
+ episode: EpisodeView | null;
64
+ reembedded: boolean;
65
+ changedFields: string[];
66
+ }> | null>;
67
+ export declare function bridgeDeleteEpisode(id: number, dbPath?: string): Promise<CrudResult<{
68
+ deleted: boolean;
69
+ }> | null>;
70
+ //# sourceMappingURL=episode-crud.d.ts.map
@@ -0,0 +1,114 @@
1
+ /**
2
+ * Episode get / list / update / delete over agentdb 3.3's ReflexionMemory (ADR-520).
3
+ *
4
+ * Episodes are what session ends and `memory distill` record, and what
5
+ * `agentdb_episode-recall` searches. agentdb 3.3 keeps the id on update and moves the row,
6
+ * embedding, vector entry and keyword index together; this module only validates, bounds
7
+ * what goes back over MCP, and feature-detects older agentdb builds.
8
+ *
9
+ * @module v3/cli/memory/episode-crud
10
+ */
11
+ import { withReflexionController } from './memory-bridge.js';
12
+ const TEXT_OUT_MAX = 4_000;
13
+ const LIST_MAX = 100;
14
+ export const EPISODE_CRUD_UNAVAILABLE = 'Episode get/list/update/delete needs agentdb >= 3.3.0 with ReflexionMemory available.';
15
+ /** Strict positive integer id. "12-notes" must never reach a delete as 12. */
16
+ export function parseEpisodeId(value) {
17
+ const n = typeof value === 'number' ? value
18
+ : typeof value === 'string' && /^\d+$/.test(value.trim()) ? Number(value.trim())
19
+ : NaN;
20
+ return Number.isSafeInteger(n) && n > 0 ? n : null;
21
+ }
22
+ const clip = (v) => typeof v === 'string' && v.length > 0 ? v.slice(0, TEXT_OUT_MAX) : undefined;
23
+ /** Bound what goes back over MCP and drop the embedding. */
24
+ function view(e) {
25
+ return {
26
+ id: Number(e.id),
27
+ sessionId: String(e.sessionId ?? ''),
28
+ task: String(e.task ?? '').slice(0, TEXT_OUT_MAX),
29
+ ...(clip(e.input) !== undefined ? { input: clip(e.input) } : {}),
30
+ ...(clip(e.output) !== undefined ? { output: clip(e.output) } : {}),
31
+ ...(clip(e.critique) !== undefined ? { critique: clip(e.critique) } : {}),
32
+ reward: Number(e.reward ?? 0),
33
+ success: !!e.success,
34
+ ...(typeof e.latencyMs === 'number' ? { latencyMs: e.latencyMs } : {}),
35
+ ...(typeof e.tokensUsed === 'number' ? { tokensUsed: e.tokensUsed } : {}),
36
+ ...(Array.isArray(e.tags) ? { tags: e.tags.slice(0, 64) } : {}),
37
+ ...(e.metadata && typeof e.metadata === 'object' ? { metadata: e.metadata } : {}),
38
+ ...(typeof e.ts === 'number' ? { ts: e.ts } : {}),
39
+ };
40
+ }
41
+ const supports = (r, method) => typeof r?.[method] === 'function';
42
+ /** agentdb throws ValidationError subclasses for bad input; pass their message through, bounded. */
43
+ function failure(error) {
44
+ const msg = error instanceof Error ? error.message : String(error);
45
+ return { success: false, error: msg.replace(/\/[^\s:]+\//g, '<path>/').slice(0, 500) };
46
+ }
47
+ export async function bridgeGetEpisode(id, dbPath) {
48
+ return withReflexionController(dbPath, async (r) => {
49
+ if (!supports(r, 'getEpisode'))
50
+ return { success: false, error: EPISODE_CRUD_UNAVAILABLE };
51
+ try {
52
+ const e = r.getEpisode(id);
53
+ return { success: true, episode: e ? view(e) : null };
54
+ }
55
+ catch (err) {
56
+ return failure(err);
57
+ }
58
+ });
59
+ }
60
+ export async function bridgeListEpisodes(options, dbPath) {
61
+ return withReflexionController(dbPath, async (r) => {
62
+ if (!supports(r, 'listEpisodes'))
63
+ return { success: false, error: EPISODE_CRUD_UNAVAILABLE };
64
+ try {
65
+ const page = r.listEpisodes({ ...options, limit: Math.min(options.limit ?? 20, LIST_MAX) });
66
+ return {
67
+ success: true,
68
+ episodes: page.items.map(view),
69
+ total: Number(page.total),
70
+ limit: Number(page.limit),
71
+ offset: Number(page.offset),
72
+ };
73
+ }
74
+ catch (err) {
75
+ return failure(err);
76
+ }
77
+ });
78
+ }
79
+ export async function bridgeUpdateEpisode(id, patch, options = {}, dbPath) {
80
+ return withReflexionController(dbPath, async (r) => {
81
+ if (!supports(r, 'updateEpisode'))
82
+ return { success: false, error: EPISODE_CRUD_UNAVAILABLE };
83
+ try {
84
+ const res = await r.updateEpisode(id, patch, { replaceMetadata: options.replaceMetadata === true });
85
+ if (!res)
86
+ return { success: true, episode: null, reembedded: false, changedFields: [] };
87
+ return {
88
+ success: true,
89
+ episode: view(res.episode),
90
+ reembedded: !!res.reembedded,
91
+ changedFields: Array.isArray(res.changedFields) ? res.changedFields : [],
92
+ };
93
+ }
94
+ catch (err) {
95
+ return failure(err);
96
+ }
97
+ });
98
+ }
99
+ export async function bridgeDeleteEpisode(id, dbPath) {
100
+ return withReflexionController(dbPath, async (r) => {
101
+ // deleteEpisode predates 3.3, but before 3.3 it parsed ids with parseInt and never removed
102
+ // the vector entry; gate on getEpisode so only the fixed implementation is used.
103
+ if (!supports(r, 'getEpisode') || !supports(r, 'deleteEpisode')) {
104
+ return { success: false, error: EPISODE_CRUD_UNAVAILABLE };
105
+ }
106
+ try {
107
+ return { success: true, deleted: (await r.deleteEpisode(id)) === true };
108
+ }
109
+ catch (err) {
110
+ return failure(err);
111
+ }
112
+ });
113
+ }
114
+ //# sourceMappingURL=episode-crud.js.map
@@ -125,6 +125,13 @@ export interface EWCStats {
125
125
  /** Storage size in bytes */
126
126
  storageSizeBytes: number;
127
127
  }
128
+ /**
129
+ * #3475: `CLAUDE_FLOW_FISHER_DECAY` overrides the default Fisher EMA decay
130
+ * rate. Only a finite number in (0, 1] is honoured; anything else is ignored
131
+ * and the default stands. An explicit `fisherDecayRate` passed to the
132
+ * constructor still wins.
133
+ */
134
+ export declare function fisherDecayRateFromEnv(env?: NodeJS.ProcessEnv): number | undefined;
128
135
  /**
129
136
  * EWC++ Consolidator
130
137
  * Implements Elastic Weight Consolidation with online updates
@@ -44,6 +44,19 @@ const DEFAULT_EWC_CONFIG = {
44
44
  onlineMode: true,
45
45
  dimensions: 384
46
46
  };
47
+ /**
48
+ * #3475: `CLAUDE_FLOW_FISHER_DECAY` overrides the default Fisher EMA decay
49
+ * rate. Only a finite number in (0, 1] is honoured; anything else is ignored
50
+ * and the default stands. An explicit `fisherDecayRate` passed to the
51
+ * constructor still wins.
52
+ */
53
+ export function fisherDecayRateFromEnv(env = process.env) {
54
+ const raw = env.CLAUDE_FLOW_FISHER_DECAY;
55
+ if (raw === undefined || raw.trim() === '')
56
+ return undefined;
57
+ const value = Number(raw);
58
+ return Number.isFinite(value) && value > 0 && value <= 1 ? value : undefined;
59
+ }
47
60
  // ============================================================================
48
61
  // EWC Consolidator Class
49
62
  // ============================================================================
@@ -60,7 +73,12 @@ export class EWCConsolidator {
60
73
  consolidationHistory = [];
61
74
  initialized = false;
62
75
  constructor(config) {
63
- this.config = { ...DEFAULT_EWC_CONFIG, ...config };
76
+ const envDecay = fisherDecayRateFromEnv();
77
+ this.config = {
78
+ ...DEFAULT_EWC_CONFIG,
79
+ ...(envDecay !== undefined ? { fisherDecayRate: envDecay } : {}),
80
+ ...config,
81
+ };
64
82
  this.globalFisher = new Array(this.config.dimensions).fill(0);
65
83
  }
66
84
  /**
@@ -544,6 +544,11 @@ export declare function bridgeRecallEpisodes(options: EpisodeRecallOptions & {
544
544
  hybrid: boolean;
545
545
  rerank: boolean;
546
546
  } | null>;
547
+ /**
548
+ * Run `fn` against the ReflexionMemory controller inside one bridge operation, so a shutdown waits
549
+ * for it (ADR-520). Null when the bridge or the controller is unavailable.
550
+ */
551
+ export declare function withReflexionController<T>(dbPath: string | undefined, fn: (reflexion: any) => Promise<T>): Promise<T | null>;
547
552
  /**
548
553
  * Start a session with ReflexionMemory episodic replay.
549
554
  * Loads relevant past session patterns for the new session.
@@ -2956,6 +2956,8 @@ export async function bridgeDeleteCausalNode(options) {
2956
2956
  const EPISODE_TASK_MAX = 4_000;
2957
2957
  const EPISODE_TEXT_MAX = 2_000;
2958
2958
  const EPISODE_RECALL_MAX = 50;
2959
+ /** #3908: upper bound on the session-end NightlyLearner sweep. */
2960
+ const SESSION_END_CONSOLIDATE_TIMEOUT_MS = 10_000;
2959
2961
  /** Null when the registry has no ReflexionMemory with retrieveRelevant. */
2960
2962
  async function recallEpisodesFrom(registry, options) {
2961
2963
  const reflexion = registry.get('reflexion');
@@ -3010,6 +3012,17 @@ export async function bridgeRecallEpisodes(options) {
3010
3012
  rerank: options.rerank === true,
3011
3013
  };
3012
3014
  }
3015
+ /**
3016
+ * Run `fn` against the ReflexionMemory controller inside one bridge operation, so a shutdown waits
3017
+ * for it (ADR-520). Null when the bridge or the controller is unavailable.
3018
+ */
3019
+ export async function withReflexionController(dbPath, fn) {
3020
+ if (!operationContext.getStore()?.active)
3021
+ return withBridgeOperation(() => withReflexionController(dbPath, fn));
3022
+ const registry = await getRegistry(dbPath);
3023
+ const reflexion = registry?.get?.('reflexion');
3024
+ return reflexion ? fn(reflexion) : null;
3025
+ }
3013
3026
  // ===== Phase 5: ReflexionMemory session lifecycle =====
3014
3027
  /**
3015
3028
  * Start a session with ReflexionMemory episodic replay.
@@ -3138,14 +3151,36 @@ export async function bridgeSessionEnd(options) {
3138
3151
  controller = controller === 'none' ? 'bridge-store' : controller + '+bridge-store';
3139
3152
  persisted = true;
3140
3153
  }
3141
- // Phase 3: Trigger NightlyLearner consolidation if available
3154
+ // Phase 3: Trigger NightlyLearner consolidation if available.
3155
+ // #3908: neither the MemoryConsolidator wrapper nor AgentDB's NightlyLearner
3156
+ // has `consolidate` — they expose `run`/`runAll` — so probing only for
3157
+ // `consolidate` meant session-end never consolidated. Bounded so a slow
3158
+ // sweep cannot hold session-end open.
3142
3159
  const nightlyLearner = registry.get('nightlyLearner');
3143
- if (nightlyLearner && typeof nightlyLearner.consolidate === 'function') {
3160
+ const consolidate = nightlyLearner && (typeof nightlyLearner.consolidate === 'function'
3161
+ ? () => nightlyLearner.consolidate({ sessionId: options.sessionId })
3162
+ : typeof nightlyLearner.run === 'function'
3163
+ ? () => nightlyLearner.run()
3164
+ : typeof nightlyLearner.runAll === 'function'
3165
+ ? () => nightlyLearner.runAll()
3166
+ : null);
3167
+ if (consolidate) {
3168
+ let timer;
3144
3169
  try {
3145
- await nightlyLearner.consolidate({ sessionId: options.sessionId });
3170
+ await Promise.race([
3171
+ Promise.resolve().then(consolidate),
3172
+ new Promise((_, reject) => {
3173
+ timer = setTimeout(() => reject(new Error('nightlyLearner timeout')), SESSION_END_CONSOLIDATE_TIMEOUT_MS);
3174
+ timer.unref?.();
3175
+ }),
3176
+ ]);
3146
3177
  controller += '+nightlyLearner';
3147
3178
  }
3148
3179
  catch { /* non-fatal */ }
3180
+ finally {
3181
+ if (timer)
3182
+ clearTimeout(timer);
3183
+ }
3149
3184
  }
3150
3185
  return { success: true, controller, persisted, ...(episodeId !== undefined ? { episodeId } : {}) };
3151
3186
  }
@@ -388,7 +388,6 @@ export declare const catalogEntrySchema: z.ZodObject<{
388
388
  }>, "many">;
389
389
  notes: z.ZodArray<z.ZodString, "many">;
390
390
  }, "strict", z.ZodTypeAny, {
391
- status: "documentation" | "shipped" | "source-only";
392
391
  sources: {
393
392
  digest: string;
394
393
  sourcePath: string;
@@ -399,6 +398,7 @@ export declare const catalogEntrySchema: z.ZodObject<{
399
398
  shippedIn: string[];
400
399
  initCategory?: string | undefined;
401
400
  }[];
401
+ status: "documentation" | "shipped" | "source-only";
402
402
  divergent: boolean;
403
403
  definition: {
404
404
  id: string;
@@ -429,7 +429,6 @@ export declare const catalogEntrySchema: z.ZodObject<{
429
429
  };
430
430
  notes: string[];
431
431
  }, {
432
- status: "documentation" | "shipped" | "source-only";
433
432
  sources: {
434
433
  digest: string;
435
434
  sourcePath: string;
@@ -440,6 +439,7 @@ export declare const catalogEntrySchema: z.ZodObject<{
440
439
  shippedIn: string[];
441
440
  initCategory?: string | undefined;
442
441
  }[];
442
+ status: "documentation" | "shipped" | "source-only";
443
443
  divergent: boolean;
444
444
  definition: {
445
445
  id: string;
@@ -654,7 +654,6 @@ export declare const commandCatalogSchema: z.ZodObject<{
654
654
  }>, "many">;
655
655
  notes: z.ZodArray<z.ZodString, "many">;
656
656
  }, "strict", z.ZodTypeAny, {
657
- status: "documentation" | "shipped" | "source-only";
658
657
  sources: {
659
658
  digest: string;
660
659
  sourcePath: string;
@@ -665,6 +664,7 @@ export declare const commandCatalogSchema: z.ZodObject<{
665
664
  shippedIn: string[];
666
665
  initCategory?: string | undefined;
667
666
  }[];
667
+ status: "documentation" | "shipped" | "source-only";
668
668
  divergent: boolean;
669
669
  definition: {
670
670
  id: string;
@@ -695,7 +695,6 @@ export declare const commandCatalogSchema: z.ZodObject<{
695
695
  };
696
696
  notes: string[];
697
697
  }, {
698
- status: "documentation" | "shipped" | "source-only";
699
698
  sources: {
700
699
  digest: string;
701
700
  sourcePath: string;
@@ -706,6 +705,7 @@ export declare const commandCatalogSchema: z.ZodObject<{
706
705
  shippedIn: string[];
707
706
  initCategory?: string | undefined;
708
707
  }[];
708
+ status: "documentation" | "shipped" | "source-only";
709
709
  divergent: boolean;
710
710
  definition: {
711
711
  id: string;
@@ -738,7 +738,6 @@ export declare const commandCatalogSchema: z.ZodObject<{
738
738
  }>, "many">;
739
739
  }, "strict", z.ZodTypeAny, {
740
740
  entries: {
741
- status: "documentation" | "shipped" | "source-only";
742
741
  sources: {
743
742
  digest: string;
744
743
  sourcePath: string;
@@ -749,6 +748,7 @@ export declare const commandCatalogSchema: z.ZodObject<{
749
748
  shippedIn: string[];
750
749
  initCategory?: string | undefined;
751
750
  }[];
751
+ status: "documentation" | "shipped" | "source-only";
752
752
  divergent: boolean;
753
753
  definition: {
754
754
  id: string;
@@ -784,7 +784,6 @@ export declare const commandCatalogSchema: z.ZodObject<{
784
784
  sourceDigest: string;
785
785
  }, {
786
786
  entries: {
787
- status: "documentation" | "shipped" | "source-only";
788
787
  sources: {
789
788
  digest: string;
790
789
  sourcePath: string;
@@ -795,6 +794,7 @@ export declare const commandCatalogSchema: z.ZodObject<{
795
794
  shippedIn: string[];
796
795
  initCategory?: string | undefined;
797
796
  }[];
797
+ status: "documentation" | "shipped" | "source-only";
798
798
  divergent: boolean;
799
799
  definition: {
800
800
  id: string;
@@ -0,0 +1,81 @@
1
+ /** Fixed-destination, tool-free Messages adapter. Credentials remain in host memory.
2
+ * No provider fallback, endpoint override, subprocess, tools, retries or logging.
3
+ */
4
+ import { type GlobalAiBudget } from './global-ai-budget.js';
5
+ import { type ContextAdapter } from './context-delegation.js';
6
+ export interface AnthropicContextPricing {
7
+ model: string;
8
+ inputUsdPerMillion: number;
9
+ outputUsdPerMillion: number;
10
+ cacheReadUsdPerMillion: number;
11
+ cacheWrite5mUsdPerMillion: number;
12
+ cacheWrite1hUsdPerMillion: number;
13
+ source: string;
14
+ observedAt: string;
15
+ }
16
+ export interface AnthropicContextAuthorization {
17
+ action: 'context.read.delegate';
18
+ endpoints: readonly ['https://api.anthropic.com/v1/messages/count_tokens', 'https://api.anthropic.com/v1/messages'];
19
+ model: string;
20
+ requestSha256: string;
21
+ sourceHashes: ReadonlyArray<Readonly<{
22
+ path: string;
23
+ sha256: string;
24
+ }>>;
25
+ requestBytes: number;
26
+ countRequestBytes: number;
27
+ totalRequestBytes: number;
28
+ inputTokenCeiling: number;
29
+ outputTokenCeiling: number;
30
+ costCeilingUsd: number;
31
+ concurrency: 1;
32
+ tools: readonly [];
33
+ }
34
+ export interface AnthropicContextUsage {
35
+ inputTokens: number;
36
+ outputTokens: number;
37
+ cacheReadInputTokens: number;
38
+ cacheCreationInputTokens: number;
39
+ cacheWrite5mInputTokens: number;
40
+ cacheWrite1hInputTokens: number;
41
+ }
42
+ export interface AnthropicContextCallReceipt {
43
+ requestSha256: string;
44
+ requestedModel: string;
45
+ actualModel?: string;
46
+ requestId?: string;
47
+ stopReason?: string;
48
+ status: 'succeeded' | 'failed';
49
+ stage: string;
50
+ durationMs: number;
51
+ countedInputTokens?: number;
52
+ usage?: AnthropicContextUsage;
53
+ /** Computed from captured usage and supplied prices; never invoice proof. */
54
+ usagePricedCostUsd?: number;
55
+ pricing: AnthropicContextPricing;
56
+ }
57
+ export interface AnthropicContextAdapterOptions {
58
+ apiKey: string;
59
+ model: string;
60
+ workspace: string;
61
+ pricing: AnthropicContextPricing;
62
+ maxOutputTokens: number;
63
+ maxCostUsd: number;
64
+ /** Mandatory host policy gate, with no source content or credential arguments.
65
+ * Host must retain/reduce its inherited envelope, never construct broader authority.
66
+ */
67
+ authorize: (request: Readonly<AnthropicContextAuthorization>, signal: AbortSignal) => Promise<boolean>;
68
+ /** Trusted runtime port; default is the existing user-global launch fuse. */
69
+ budget?: Pick<GlobalAiBudget, 'reserve' | 'release' | 'recordQuotaError'> & Partial<Pick<GlobalAiBudget, 'recordUsage'>>;
70
+ maxResponseBytes?: number;
71
+ timeoutMs?: number;
72
+ }
73
+ export interface GovernedAnthropicContextAdapter extends ContextAdapter {
74
+ receipts(): readonly Readonly<AnthropicContextCallReceipt>[];
75
+ }
76
+ /** No inference happens until host authorization and a global launch permit.
77
+ * Uses token counting before generation, retaining one global slot across both
78
+ * requests. At most one count request and one generation, never a retry.
79
+ */
80
+ export declare function createAnthropicContextAdapter(options: AnthropicContextAdapterOptions): GovernedAnthropicContextAdapter;
81
+ //# sourceMappingURL=anthropic-context-adapter.d.ts.map