@kognai/clawrouter-x402 0.1.0 → 0.1.1

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.
@@ -21,7 +21,7 @@
21
21
  * @see ~/Documents/Kognai/Master Documents/clawrouter_spec_v2.docx
22
22
  * @see ~/Documents/Kognai/Master Documents/execution_protocol_sections_17_18.docx
23
23
  */
24
- import type { TierClass, TextComplexity, CreativeModality, CreativeQuality, ClawRouterV2Request, ClawRouterV2Response } from '../../orchestrator-core/src/lib/model-router-contract';
24
+ import type { TierClass, TextComplexity, CreativeModality, CreativeQuality, ClawRouterV2Request, ClawRouterV2Response } from '@kognai/orchestrator-core';
25
25
  export type { TierClass, TextComplexity, CreativeModality, CreativeQuality, ClawRouterV2Request, ClawRouterV2Response, };
26
26
  interface CostLogEntry {
27
27
  timestamp: string;
@@ -67,8 +67,8 @@ const https = __importStar(require("https"));
67
67
  const fs = __importStar(require("fs"));
68
68
  const path = __importStar(require("path"));
69
69
  const crypto = __importStar(require("crypto"));
70
- const wallet_state_1 = require("../../orchestrator-core/src/lib/wallet-state");
71
- const acp_1 = require("../../orchestrator-core/src/lib/acp");
70
+ const orchestrator_core_1 = require("@kognai/orchestrator-core");
71
+ const orchestrator_core_2 = require("@kognai/orchestrator-core");
72
72
  // ── Config ────────────────────────────────────────────────────────────────────
73
73
  const _rawOllamaHost = process.env.OLLAMA_HOST || 'http://127.0.0.1:11434'; // SEC1: loopback-only default
74
74
  const OLLAMA_BASE = _rawOllamaHost.startsWith('http') ? _rawOllamaHost : `http://${_rawOllamaHost}`;
@@ -654,7 +654,7 @@ async function routeCall(req) {
654
654
  // = log only; flip to `enforce` to actually downgrade after reviewing shadow logs).
655
655
  if (!route.local && req.tier_class === 'text') {
656
656
  const gateMode = (process.env.X402_SPEND_GATE || 'shadow').toLowerCase();
657
- if (gateMode !== 'off' && (0, acp_1.getAgent)(req.agent_id) && !(0, acp_1.checkCapability)(req.agent_id, 'llm_call_cloud').allowed) {
657
+ if (gateMode !== 'off' && (0, orchestrator_core_2.getAgent)(req.agent_id) && !(0, orchestrator_core_2.checkCapability)(req.agent_id, 'llm_call_cloud').allowed) {
658
658
  console.warn(`[ClawRouter] spend-gate(${gateMode}): agent "${req.agent_id}" lacks llm_call_cloud — ` +
659
659
  `${route.tier} ${gateMode === 'enforce' ? 'downgraded → T2 local' : 'WOULD be downgraded'}`);
660
660
  if (gateMode === 'enforce') {
@@ -664,7 +664,7 @@ async function routeCall(req) {
664
664
  }
665
665
  // 1b. CEO Wallet freeze guard — block cloud calls when budget exhausted (§17.5)
666
666
  if (!route.local) {
667
- const wallet = (0, wallet_state_1.getWalletState)();
667
+ const wallet = (0, orchestrator_core_1.getWalletState)();
668
668
  if (wallet.isFrozen) {
669
669
  throw new Error(`ClawRouter FROZEN: CEO wallet at ${wallet.burnPct.toFixed(1)}% ` +
670
670
  `($${wallet.spentThisMonth.toFixed(2)}/$${wallet.monthlyBudget}). ` +
@@ -712,7 +712,7 @@ async function routeCall(req) {
712
712
  output_tokens += apexResult.output_tokens;
713
713
  cost_usd = apexResult.cost_usd;
714
714
  if (cost_usd > 0)
715
- (0, wallet_state_1.recordSpend)(cost_usd);
715
+ (0, orchestrator_core_1.recordSpend)(cost_usd);
716
716
  route = { tier: 'T3', model: TIER_MODELS.T3_APEX, local: false };
717
717
  }
718
718
  }
@@ -732,7 +732,7 @@ async function routeCall(req) {
732
732
  }
733
733
  // 4b. CEO Wallet billing — record every cloud spend (§17.5)
734
734
  if (cost_usd > 0) {
735
- (0, wallet_state_1.recordSpend)(cost_usd);
735
+ (0, orchestrator_core_1.recordSpend)(cost_usd);
736
736
  }
737
737
  // 4c. x402 on-chain metering (Option B): when enabled, every cloud-tier
738
738
  // call broadcasts a small EIP-3009 USDC transfer from the x402 signer
@@ -11,7 +11,7 @@
11
11
  * clawrouter-v2.ts), so importing this module does not eagerly pull viem —
12
12
  * but the package declares viem as a dependency so it resolves at pay time.
13
13
  */
14
- import type { ModelRouter } from '../../orchestrator-core/src/lib/model-router-contract';
14
+ import type { ModelRouter } from '@kognai/orchestrator-core';
15
15
  /**
16
16
  * The ModelRouter implementation Kognai injects:
17
17
  * import { x402Router } from '@kognai/clawrouter-x402';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kognai/clawrouter-x402",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "private": false,
5
5
  "description": "ClawRouter v2 — Kognai's viem-backed x402 ModelRouter implementation. Injected into @kognai/orchestrator-core's router seam at startup, so core never depends on viem; products that don't route on-chain simply don't install this package.",
6
6
  "main": "dist/index.js",
@@ -29,5 +29,8 @@
29
29
  },
30
30
  "engines": {
31
31
  "node": ">=18"
32
+ },
33
+ "devDependencies": {
34
+ "@kognai/orchestrator-core": "^0.1.0"
32
35
  }
33
36
  }
@@ -1,61 +0,0 @@
1
- /**
2
- * ACP — Agent Capability Protocol v1
3
- *
4
- * Defines capability declarations for each agent in the Kognai swarm.
5
- * Each agent declares what it CAN and CANNOT do, enabling:
6
- * - Constitution enforcement (prevent agents from exceeding scope)
7
- * - CTO approval gate capability checks
8
- * - Task routing based on declared capabilities
9
- *
10
- * Capability tiers:
11
- * T1 (Foundation): read, write, search
12
- * T2 (Content): llm_call, tts, video_gen, script_gen
13
- * T3 (Integration): api_call, db_query, telegram, stripe
14
- * T4 (System): deploy, pm2, git_push, shell_exec
15
- *
16
- * Sprint 650 — ACP v1 implementation
17
- */
18
- export type CapabilityTier = 'T1' | 'T2' | 'T3' | 'T4';
19
- export type Capability = 'read_files' | 'write_files' | 'search_code' | 'git_read' | 'llm_call_local' | 'llm_call_cloud' | 'tts_generate' | 'video_composite' | 'script_generate' | 'image_generate' | 'avatar_generate' | 'api_call_external' | 'db_query' | 'db_write' | 'telegram_send' | 'stripe_read' | 'stripe_write' | 'youtube_read' | 'tiktok_post' | 'deploy' | 'pm2_manage' | 'git_push' | 'shell_exec' | 'env_modify';
20
- export interface AgentCapabilityDeclaration {
21
- agent_id: string;
22
- display_name: string;
23
- tier: CapabilityTier;
24
- capabilities: Capability[];
25
- denied: Capability[];
26
- scope: string;
27
- max_model_tier: 'nano' | 'local' | 'power' | 'cloud' | 'apex';
28
- }
29
- export interface CapabilityCheckResult {
30
- allowed: boolean;
31
- agent_id: string;
32
- capability: Capability;
33
- reason: string;
34
- }
35
- /** Get all registered agents */
36
- export declare function getAllAgents(): AgentCapabilityDeclaration[];
37
- /** Get a specific agent by ID */
38
- export declare function getAgent(agentId: string): AgentCapabilityDeclaration | undefined;
39
- /** Check if an agent has a specific capability */
40
- export declare function checkCapability(agentId: string, capability: Capability): CapabilityCheckResult;
41
- /** Check multiple capabilities at once */
42
- export declare function checkCapabilities(agentId: string, capabilities: Capability[]): CapabilityCheckResult[];
43
- /** Get all agents with a specific capability */
44
- export declare function getAgentsWithCapability(capability: Capability): AgentCapabilityDeclaration[];
45
- /** Get the tier for a capability */
46
- export declare function getCapabilityTier(capability: Capability): CapabilityTier | undefined;
47
- /** Validate that a sprint's task assignments respect ACP */
48
- export declare function validateSprintAssignments(tasks: Array<{
49
- agent: string;
50
- required_capabilities: Capability[];
51
- }>): {
52
- valid: boolean;
53
- violations: CapabilityCheckResult[];
54
- };
55
- /** Get summary stats */
56
- export declare function getRegistryStats(): {
57
- total_agents: number;
58
- by_tier: Record<CapabilityTier, number>;
59
- kognai_agents: number;
60
- scs001_agents: number;
61
- };
@@ -1,425 +0,0 @@
1
- "use strict";
2
- /**
3
- * ACP — Agent Capability Protocol v1
4
- *
5
- * Defines capability declarations for each agent in the Kognai swarm.
6
- * Each agent declares what it CAN and CANNOT do, enabling:
7
- * - Constitution enforcement (prevent agents from exceeding scope)
8
- * - CTO approval gate capability checks
9
- * - Task routing based on declared capabilities
10
- *
11
- * Capability tiers:
12
- * T1 (Foundation): read, write, search
13
- * T2 (Content): llm_call, tts, video_gen, script_gen
14
- * T3 (Integration): api_call, db_query, telegram, stripe
15
- * T4 (System): deploy, pm2, git_push, shell_exec
16
- *
17
- * Sprint 650 — ACP v1 implementation
18
- */
19
- Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.getAllAgents = getAllAgents;
21
- exports.getAgent = getAgent;
22
- exports.checkCapability = checkCapability;
23
- exports.checkCapabilities = checkCapabilities;
24
- exports.getAgentsWithCapability = getAgentsWithCapability;
25
- exports.getCapabilityTier = getCapabilityTier;
26
- exports.validateSprintAssignments = validateSprintAssignments;
27
- exports.getRegistryStats = getRegistryStats;
28
- // ── Capability Tier Map ───────────────────────────────────────────────
29
- const TIER_CAPABILITIES = {
30
- T1: ['read_files', 'write_files', 'search_code', 'git_read'],
31
- T2: ['llm_call_local', 'llm_call_cloud', 'tts_generate', 'video_composite',
32
- 'script_generate', 'image_generate', 'avatar_generate'],
33
- T3: ['api_call_external', 'db_query', 'db_write', 'telegram_send',
34
- 'stripe_read', 'stripe_write', 'youtube_read', 'tiktok_post'],
35
- T4: ['deploy', 'pm2_manage', 'git_push', 'shell_exec', 'env_modify'],
36
- };
37
- // ── Agent Registry ────────────────────────────────────────────────────
38
- const REGISTRY = [
39
- // ─── Kognai Core Agents ─────────────────────────────────
40
- {
41
- agent_id: 'ceo', display_name: 'CEO', tier: 'T4',
42
- capabilities: ['read_files', 'write_files', 'search_code', 'git_read', 'llm_call_local', 'llm_call_cloud', 'shell_exec', 'git_push'],
43
- denied: ['stripe_write', 'tiktok_post', 'env_modify'],
44
- scope: 'Strategy, vision, agent coordination. No financial ops or posting.',
45
- max_model_tier: 'apex',
46
- },
47
- {
48
- agent_id: 'cto', display_name: 'CTO', tier: 'T4',
49
- capabilities: ['read_files', 'write_files', 'search_code', 'git_read', 'llm_call_local', 'llm_call_cloud', 'shell_exec', 'git_push', 'deploy', 'pm2_manage'],
50
- denied: ['stripe_write', 'tiktok_post'],
51
- scope: 'Architecture review, sprint approval, deployment, infra management.',
52
- max_model_tier: 'cloud',
53
- },
54
- {
55
- agent_id: 'cfo', display_name: 'CFO', tier: 'T3',
56
- capabilities: ['read_files', 'search_code', 'git_read', 'llm_call_local', 'stripe_read', 'db_query'],
57
- denied: ['write_files', 'shell_exec', 'git_push', 'deploy', 'stripe_write'],
58
- scope: 'Financial reporting, cost tracking, budget analysis. Read-only financial access.',
59
- max_model_tier: 'power',
60
- },
61
- {
62
- agent_id: 'cmo', display_name: 'CMO', tier: 'T2',
63
- capabilities: ['read_files', 'write_files', 'search_code', 'git_read', 'llm_call_local'],
64
- denied: ['shell_exec', 'deploy', 'db_write', 'stripe_write'],
65
- scope: 'Marketing strategy, content planning, brand narrative.',
66
- max_model_tier: 'power',
67
- },
68
- {
69
- agent_id: 'supervisor', display_name: 'Supervisor', tier: 'T3',
70
- capabilities: ['read_files', 'search_code', 'git_read', 'llm_call_local', 'db_query'],
71
- denied: ['write_files', 'shell_exec', 'deploy', 'git_push'],
72
- scope: 'Sprint review, quality validation. Read-only analysis.',
73
- max_model_tier: 'power',
74
- },
75
- {
76
- agent_id: 'devops', display_name: 'DevOps', tier: 'T4',
77
- capabilities: ['read_files', 'write_files', 'search_code', 'git_read', 'shell_exec', 'deploy', 'pm2_manage', 'git_push', 'env_modify'],
78
- denied: ['stripe_write', 'tiktok_post', 'llm_call_cloud'],
79
- scope: 'Infrastructure, deployment, monitoring, PM2 process management.',
80
- max_model_tier: 'power',
81
- },
82
- {
83
- agent_id: 'security', display_name: 'Security', tier: 'T3',
84
- capabilities: ['read_files', 'search_code', 'git_read', 'llm_call_local', 'db_query'],
85
- denied: ['write_files', 'shell_exec', 'deploy', 'git_push', 'db_write'],
86
- scope: 'Security audit, vulnerability scanning. Read-only.',
87
- max_model_tier: 'power',
88
- },
89
- {
90
- agent_id: 'achiri', display_name: 'Achiri', tier: 'T3',
91
- capabilities: ['read_files', 'write_files', 'llm_call_local', 'llm_call_cloud', 'db_query', 'db_write', 'telegram_send'],
92
- denied: ['shell_exec', 'deploy', 'git_push', 'stripe_write'],
93
- scope: 'AI companion conversations, memory, Tunisian cultural adaptation.',
94
- max_model_tier: 'cloud',
95
- },
96
- {
97
- agent_id: 'backend-core', display_name: 'Backend Core', tier: 'T3',
98
- capabilities: ['read_files', 'write_files', 'search_code', 'git_read', 'db_query', 'db_write', 'api_call_external'],
99
- denied: ['deploy', 'shell_exec', 'stripe_write'],
100
- scope: 'Backend API development, database operations.',
101
- max_model_tier: 'power',
102
- },
103
- {
104
- agent_id: 'backend-ledger', display_name: 'Backend Ledger', tier: 'T3',
105
- capabilities: ['read_files', 'write_files', 'search_code', 'git_read', 'db_query', 'db_write'],
106
- denied: ['deploy', 'shell_exec', 'stripe_write'],
107
- scope: 'Ledger management, financial record keeping.',
108
- max_model_tier: 'power',
109
- },
110
- {
111
- agent_id: 'backend-tax', display_name: 'Backend Tax', tier: 'T3',
112
- capabilities: ['read_files', 'write_files', 'search_code', 'git_read', 'db_query'],
113
- denied: ['deploy', 'shell_exec', 'stripe_write', 'db_write'],
114
- scope: 'Tax calculation logic. Read-only DB.',
115
- max_model_tier: 'local',
116
- },
117
- {
118
- agent_id: 'bizdev', display_name: 'BizDev', tier: 'T2',
119
- capabilities: ['read_files', 'write_files', 'search_code', 'git_read', 'llm_call_local'],
120
- denied: ['shell_exec', 'deploy', 'db_write', 'stripe_write'],
121
- scope: 'Business development strategy and research.',
122
- max_model_tier: 'power',
123
- },
124
- {
125
- agent_id: 'conflict-analyzer', display_name: 'Conflict Analyzer', tier: 'T1',
126
- capabilities: ['read_files', 'search_code', 'git_read'],
127
- denied: ['write_files', 'shell_exec', 'deploy', 'db_write'],
128
- scope: 'Detect conflicts between agent outputs. Read-only.',
129
- max_model_tier: 'local',
130
- },
131
- {
132
- agent_id: 'conway-integration', display_name: 'Conway Integration', tier: 'T2',
133
- capabilities: ['read_files', 'write_files', 'search_code', 'git_read', 'llm_call_local'],
134
- denied: ['shell_exec', 'deploy', 'db_write'],
135
- scope: 'Conway governance protocol integration.',
136
- max_model_tier: 'power',
137
- },
138
- {
139
- agent_id: 'execution-verifier', display_name: 'Execution Verifier', tier: 'T1',
140
- capabilities: ['read_files', 'search_code', 'git_read'],
141
- denied: ['write_files', 'shell_exec', 'deploy'],
142
- scope: 'Verify sprint execution results. Read-only.',
143
- max_model_tier: 'local',
144
- },
145
- {
146
- agent_id: 'execution-watchdog', display_name: 'Execution Watchdog', tier: 'T2',
147
- capabilities: ['read_files', 'search_code', 'git_read', 'llm_call_local', 'telegram_send'],
148
- denied: ['write_files', 'shell_exec', 'deploy'],
149
- scope: 'Monitor execution health, alert on anomalies.',
150
- max_model_tier: 'local',
151
- },
152
- {
153
- agent_id: 'frontend', display_name: 'Frontend', tier: 'T2',
154
- capabilities: ['read_files', 'write_files', 'search_code', 'git_read', 'llm_call_local'],
155
- denied: ['shell_exec', 'deploy', 'db_write', 'stripe_write'],
156
- scope: 'Frontend UI development.',
157
- max_model_tier: 'power',
158
- },
159
- {
160
- agent_id: 'invoica-x-admin', display_name: 'Invoica X Admin', tier: 'T3',
161
- capabilities: ['read_files', 'write_files', 'search_code', 'git_read', 'api_call_external'],
162
- denied: ['shell_exec', 'deploy', 'db_write'],
163
- scope: 'Invoica cross-product administration.',
164
- max_model_tier: 'power',
165
- },
166
- {
167
- agent_id: 'market-intelligence', display_name: 'Market Intelligence', tier: 'T3',
168
- capabilities: ['read_files', 'write_files', 'search_code', 'git_read', 'llm_call_local', 'api_call_external'],
169
- denied: ['shell_exec', 'deploy', 'db_write'],
170
- scope: 'Market research, competitor analysis, trend tracking.',
171
- max_model_tier: 'power',
172
- },
173
- {
174
- agent_id: 'pipeline-health-monitor', display_name: 'Pipeline Health Monitor', tier: 'T3',
175
- capabilities: ['read_files', 'search_code', 'git_read', 'db_query', 'telegram_send'],
176
- denied: ['write_files', 'shell_exec', 'deploy'],
177
- scope: 'Monitor pipeline health metrics, send alerts.',
178
- max_model_tier: 'local',
179
- },
180
- {
181
- agent_id: 'skills', display_name: 'Skills Manager', tier: 'T2',
182
- capabilities: ['read_files', 'write_files', 'search_code', 'git_read', 'llm_call_local'],
183
- denied: ['shell_exec', 'deploy', 'db_write'],
184
- scope: 'OpenClaw skills registry management.',
185
- max_model_tier: 'power',
186
- },
187
- {
188
- agent_id: 'sprint-retrospective', display_name: 'Sprint Retrospective', tier: 'T2',
189
- capabilities: ['read_files', 'write_files', 'search_code', 'git_read', 'llm_call_local'],
190
- denied: ['shell_exec', 'deploy', 'db_write'],
191
- scope: 'Sprint analysis and retrospective reports.',
192
- max_model_tier: 'power',
193
- },
194
- {
195
- agent_id: 'telegram-support', display_name: 'Telegram Support', tier: 'T3',
196
- capabilities: ['read_files', 'search_code', 'git_read', 'telegram_send', 'llm_call_local'],
197
- denied: ['write_files', 'shell_exec', 'deploy', 'db_write'],
198
- scope: 'Telegram bot command handling and notifications.',
199
- max_model_tier: 'local',
200
- },
201
- {
202
- agent_id: 'test-failure-predictor', display_name: 'Test Failure Predictor', tier: 'T1',
203
- capabilities: ['read_files', 'search_code', 'git_read'],
204
- denied: ['write_files', 'shell_exec', 'deploy'],
205
- scope: 'Predict likely test failures from code changes.',
206
- max_model_tier: 'local',
207
- },
208
- {
209
- agent_id: 'test-runner', display_name: 'Test Runner', tier: 'T2',
210
- capabilities: ['read_files', 'search_code', 'git_read', 'shell_exec'],
211
- denied: ['write_files', 'deploy', 'git_push', 'db_write'],
212
- scope: 'Execute test suites. Shell access for test commands only.',
213
- max_model_tier: 'local',
214
- },
215
- {
216
- agent_id: 'test-utility-generator', display_name: 'Test Utility Generator', tier: 'T2',
217
- capabilities: ['read_files', 'write_files', 'search_code', 'git_read', 'llm_call_local'],
218
- denied: ['shell_exec', 'deploy', 'db_write'],
219
- scope: 'Generate test fixtures and utility code.',
220
- max_model_tier: 'local',
221
- },
222
- {
223
- agent_id: 'x-admin', display_name: 'X Admin', tier: 'T3',
224
- capabilities: ['read_files', 'write_files', 'search_code', 'git_read', 'api_call_external'],
225
- denied: ['shell_exec', 'deploy', 'db_write'],
226
- scope: 'X/Twitter administration and posting.',
227
- max_model_tier: 'power',
228
- },
229
- // ─── SCS-001 Pipeline Agents ────────────────────────────
230
- {
231
- agent_id: 'scs001-orchestrator', display_name: 'SCS-001 Orchestrator', tier: 'T3',
232
- capabilities: ['read_files', 'write_files', 'search_code', 'llm_call_local', 'llm_call_cloud', 'api_call_external', 'telegram_send'],
233
- denied: ['deploy', 'git_push', 'stripe_write', 'env_modify'],
234
- scope: 'Video pipeline orchestration. Coordinates all SCS-001 agents.',
235
- max_model_tier: 'cloud',
236
- },
237
- {
238
- agent_id: 'scs001-discovery', display_name: 'SCS-001 Discovery', tier: 'T3',
239
- capabilities: ['read_files', 'write_files', 'api_call_external', 'youtube_read'],
240
- denied: ['shell_exec', 'deploy', 'db_write'],
241
- scope: 'Discover trending topics and YouTube clips.',
242
- max_model_tier: 'local',
243
- },
244
- {
245
- agent_id: 'scs001-clip-detection', display_name: 'SCS-001 Clip Detection', tier: 'T2',
246
- capabilities: ['read_files', 'write_files', 'llm_call_local'],
247
- denied: ['shell_exec', 'deploy', 'api_call_external'],
248
- scope: 'Detect and score clips from downloaded videos.',
249
- max_model_tier: 'power',
250
- },
251
- {
252
- agent_id: 'scs001-insight', display_name: 'SCS-001 Insight', tier: 'T2',
253
- capabilities: ['read_files', 'write_files', 'llm_call_local', 'llm_call_cloud'],
254
- denied: ['shell_exec', 'deploy', 'api_call_external'],
255
- scope: 'Generate insight briefs from qualified clips.',
256
- max_model_tier: 'cloud',
257
- },
258
- {
259
- agent_id: 'scs001-script', display_name: 'SCS-001 Script', tier: 'T2',
260
- capabilities: ['read_files', 'write_files', 'llm_call_local', 'llm_call_cloud', 'script_generate'],
261
- denied: ['shell_exec', 'deploy', 'api_call_external'],
262
- scope: 'Generate video scripts from insight briefs. LLM rewrite.',
263
- max_model_tier: 'cloud',
264
- },
265
- {
266
- agent_id: 'scs001-script-validator', display_name: 'SCS-001 Script Validator', tier: 'T1',
267
- capabilities: ['read_files'],
268
- denied: ['write_files', 'shell_exec', 'deploy'],
269
- scope: 'Validate script bundles for quality and format compliance.',
270
- max_model_tier: 'nano',
271
- },
272
- {
273
- agent_id: 'scs001-scorer', display_name: 'SCS-001 Scorer', tier: 'T1',
274
- capabilities: ['read_files', 'write_files'],
275
- denied: ['shell_exec', 'deploy', 'api_call_external'],
276
- scope: 'Score content quality and viral potential.',
277
- max_model_tier: 'local',
278
- },
279
- {
280
- agent_id: 'scs001-editing', display_name: 'SCS-001 Editing', tier: 'T2',
281
- capabilities: ['read_files', 'write_files', 'shell_exec', 'video_composite', 'tts_generate'],
282
- denied: ['deploy', 'git_push', 'api_call_external'],
283
- scope: 'Video editing, FFmpeg composition, TTS generation.',
284
- max_model_tier: 'local',
285
- },
286
- {
287
- agent_id: 'scs001-caption', display_name: 'SCS-001 Caption', tier: 'T2',
288
- capabilities: ['read_files', 'write_files', 'shell_exec', 'video_composite'],
289
- denied: ['deploy', 'git_push'],
290
- scope: 'Burn captions and subtitles into video.',
291
- max_model_tier: 'local',
292
- },
293
- {
294
- agent_id: 'scs001-qc', display_name: 'SCS-001 QC', tier: 'T2',
295
- capabilities: ['read_files', 'write_files', 'llm_call_local'],
296
- denied: ['shell_exec', 'deploy', 'api_call_external'],
297
- scope: 'Quality control checks on finished videos.',
298
- max_model_tier: 'power',
299
- },
300
- {
301
- agent_id: 'scs001-publishing', display_name: 'SCS-001 Publishing', tier: 'T3',
302
- capabilities: ['read_files', 'write_files', 'api_call_external', 'tiktok_post', 'telegram_send'],
303
- denied: ['shell_exec', 'deploy', 'git_push'],
304
- scope: 'Publish videos to TikTok and notify via Telegram.',
305
- max_model_tier: 'local',
306
- },
307
- {
308
- agent_id: 'scs001-hosting', display_name: 'SCS-001 Hosting', tier: 'T3',
309
- capabilities: ['read_files', 'write_files', 'api_call_external'],
310
- denied: ['shell_exec', 'deploy', 'git_push'],
311
- scope: 'Upload and host video files.',
312
- max_model_tier: 'local',
313
- },
314
- {
315
- agent_id: 'scs001-analytics', display_name: 'SCS-001 Analytics', tier: 'T3',
316
- capabilities: ['read_files', 'write_files', 'db_query', 'api_call_external'],
317
- denied: ['shell_exec', 'deploy', 'db_write'],
318
- scope: 'View analytics, engagement metrics, performance tracking.',
319
- max_model_tier: 'local',
320
- },
321
- {
322
- agent_id: 'scs001-trend', display_name: 'SCS-001 Trend', tier: 'T3',
323
- capabilities: ['read_files', 'write_files', 'api_call_external', 'llm_call_local'],
324
- denied: ['shell_exec', 'deploy', 'db_write'],
325
- scope: 'Track trending topics across platforms.',
326
- max_model_tier: 'power',
327
- },
328
- {
329
- agent_id: 'scs001-experiment', display_name: 'SCS-001 Experiment', tier: 'T2',
330
- capabilities: ['read_files', 'write_files', 'llm_call_local'],
331
- denied: ['shell_exec', 'deploy', 'api_call_external'],
332
- scope: 'A/B testing framework for content optimization.',
333
- max_model_tier: 'local',
334
- },
335
- {
336
- agent_id: 'scs001-flywheel', display_name: 'SCS-001 Flywheel', tier: 'T2',
337
- capabilities: ['read_files', 'write_files', 'llm_call_local'],
338
- denied: ['shell_exec', 'deploy', 'api_call_external'],
339
- scope: 'Content flywheel optimization and feedback loops.',
340
- max_model_tier: 'local',
341
- },
342
- {
343
- agent_id: 'scs001-failure-library', display_name: 'SCS-001 Failure Library', tier: 'T1',
344
- capabilities: ['read_files', 'write_files'],
345
- denied: ['shell_exec', 'deploy', 'api_call_external'],
346
- scope: 'Track and learn from pipeline failures.',
347
- max_model_tier: 'nano',
348
- },
349
- {
350
- agent_id: 'scs001-viral-downloader', display_name: 'SCS-001 Viral Downloader', tier: 'T3',
351
- capabilities: ['read_files', 'write_files', 'api_call_external', 'shell_exec'],
352
- denied: ['deploy', 'git_push', 'db_write'],
353
- scope: 'Download viral video clips for analysis. Shell for yt-dlp.',
354
- max_model_tier: 'local',
355
- },
356
- ];
357
- // ── Public API ────────────────────────────────────────────────────────
358
- /** Get all registered agents */
359
- function getAllAgents() {
360
- return [...REGISTRY];
361
- }
362
- /** Get a specific agent by ID */
363
- function getAgent(agentId) {
364
- return REGISTRY.find(a => a.agent_id === agentId);
365
- }
366
- /** Check if an agent has a specific capability */
367
- function checkCapability(agentId, capability) {
368
- const agent = getAgent(agentId);
369
- if (!agent) {
370
- return { allowed: false, agent_id: agentId, capability, reason: `Agent "${agentId}" not registered in ACP` };
371
- }
372
- // Explicit denials always override
373
- if (agent.denied.includes(capability)) {
374
- return { allowed: false, agent_id: agentId, capability, reason: `Capability "${capability}" explicitly denied for ${agent.display_name}` };
375
- }
376
- // Check if capability is in agent's granted list
377
- if (agent.capabilities.includes(capability)) {
378
- return { allowed: true, agent_id: agentId, capability, reason: `Capability "${capability}" granted to ${agent.display_name}` };
379
- }
380
- return { allowed: false, agent_id: agentId, capability, reason: `Capability "${capability}" not declared for ${agent.display_name}` };
381
- }
382
- /** Check multiple capabilities at once */
383
- function checkCapabilities(agentId, capabilities) {
384
- return capabilities.map(cap => checkCapability(agentId, cap));
385
- }
386
- /** Get all agents with a specific capability */
387
- function getAgentsWithCapability(capability) {
388
- return REGISTRY.filter(a => a.capabilities.includes(capability) && !a.denied.includes(capability));
389
- }
390
- /** Get the tier for a capability */
391
- function getCapabilityTier(capability) {
392
- for (const [tier, caps] of Object.entries(TIER_CAPABILITIES)) {
393
- if (caps.includes(capability))
394
- return tier;
395
- }
396
- return undefined;
397
- }
398
- /** Validate that a sprint's task assignments respect ACP */
399
- function validateSprintAssignments(tasks) {
400
- const violations = [];
401
- for (const task of tasks) {
402
- for (const cap of task.required_capabilities) {
403
- const result = checkCapability(task.agent, cap);
404
- if (!result.allowed)
405
- violations.push(result);
406
- }
407
- }
408
- return { valid: violations.length === 0, violations };
409
- }
410
- /** Get summary stats */
411
- function getRegistryStats() {
412
- const byTier = { T1: 0, T2: 0, T3: 0, T4: 0 };
413
- let scs001 = 0;
414
- for (const a of REGISTRY) {
415
- byTier[a.tier]++;
416
- if (a.agent_id.startsWith('scs001-'))
417
- scs001++;
418
- }
419
- return {
420
- total_agents: REGISTRY.length,
421
- by_tier: byTier,
422
- kognai_agents: REGISTRY.length - scs001,
423
- scs001_agents: scs001,
424
- };
425
- }
@@ -1,13 +0,0 @@
1
- export interface EnginePaths {
2
- root: string;
3
- swarmState: string;
4
- sprints: string;
5
- failureLibrary: string;
6
- ksl: string;
7
- logs: string;
8
- }
9
- /**
10
- * Resolve all engine paths from a root. Precedence: explicit arg → KOGNAI_ROOT
11
- * env → process.cwd(). Individual dirs accept env overrides for non-standard layouts.
12
- */
13
- export declare function resolveEnginePaths(root?: string): EnginePaths;
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolveEnginePaths = resolveEnginePaths;
4
- /**
5
- * engine-paths.ts — TICKET-215 Phase 3: the path-parameterization seam.
6
- *
7
- * The core engine historically hardcoded repo-specific paths (.swarm-state,
8
- * data/failure-library, workspace/sprints, …) via `resolve(__dirname, '../../…')`,
9
- * which only works when the code physically lives in the consuming repo. That
10
- * coupling is what blocked packaging the engine.
11
- *
12
- * This module centralizes every repo-specific path behind a single resolver,
13
- * defaulted from `KOGNAI_ROOT` (or `process.cwd()`) so behavior is unchanged when
14
- * the engine runs from a product repo root — but now overridable, so the same
15
- * package can serve Kognai, Voxight, and Invoica from their own roots.
16
- */
17
- const path_1 = require("path");
18
- /**
19
- * Resolve all engine paths from a root. Precedence: explicit arg → KOGNAI_ROOT
20
- * env → process.cwd(). Individual dirs accept env overrides for non-standard layouts.
21
- */
22
- function resolveEnginePaths(root) {
23
- const r = root || process.env.KOGNAI_ROOT || process.cwd();
24
- return {
25
- root: r,
26
- swarmState: process.env.KOGNAI_SWARM_STATE || (0, path_1.join)(r, '.swarm-state'),
27
- sprints: process.env.KOGNAI_SPRINTS_DIR || (0, path_1.join)(r, 'workspace', 'sprints'),
28
- failureLibrary: process.env.KOGNAI_FAILURE_DIR || (0, path_1.join)(r, 'data', 'failure-library'),
29
- ksl: process.env.KOGNAI_KSL_DIR || (0, path_1.join)(r, 'workspace', 'ksl'),
30
- logs: process.env.KOGNAI_LOGS_DIR || (0, path_1.join)(r, 'logs'),
31
- };
32
- }
@@ -1,91 +0,0 @@
1
- /**
2
- * model-router-contract.ts — TICKET-215 Wave C: the engine's model-routing SEAM.
3
- *
4
- * This is the zero-dep interface that decouples the orchestrator from any
5
- * concrete router. The orchestrator depends ONLY on this contract; the actual
6
- * implementation is injected at startup (see model-router-registry.ts).
7
- *
8
- * WHY: ClawRouter v2 (the production router) imports `viem` for on-chain x402
9
- * payments. We do NOT want `viem` in @kognai/orchestrator-core — that would make
10
- * every adopter (e.g. Invoica, which never routes on-chain) carry web3. So the
11
- * viem-backed router lives OUTSIDE core (Kognai injects it); products that don't
12
- * route on-chain inject their own / use a local default. viem stays absent from
13
- * core's dependency tree entirely.
14
- *
15
- * These request/response types are the canonical source of truth — clawrouter-v2
16
- * imports them from here and re-exports for back-compat.
17
- */
18
- export type TierClass = 'text' | 'creative';
19
- export type TextComplexity = 'nano' | 'local' | 'power' | 'exec' | 'apex';
20
- export type CreativeModality = 'image' | 'video' | 'speech' | 'music' | 'transcription' | 'visual_understanding';
21
- export type CreativeQuality = 'fast' | 'high' | 'emotional';
22
- export interface ClawRouterV2Request {
23
- task_type: string;
24
- tier_class: TierClass;
25
- complexity?: TextComplexity;
26
- modality?: CreativeModality;
27
- quality?: CreativeQuality;
28
- context_tokens: number;
29
- constitutional_flag: boolean;
30
- agent_id: string;
31
- payload: {
32
- system?: string;
33
- prompt?: string;
34
- messages?: Array<{
35
- role: string;
36
- content: string;
37
- }>;
38
- [key: string]: any;
39
- };
40
- }
41
- export interface ClawRouterV2Response {
42
- content: string;
43
- model: string;
44
- tier: string;
45
- local: boolean;
46
- cost_usd: number;
47
- input_tokens: number;
48
- output_tokens: number;
49
- qcg_compressed: boolean;
50
- tokens_saved_by_qcg: number;
51
- agent_id: string;
52
- task_type: string;
53
- timestamp: string;
54
- }
55
- export interface CallLLMOptions {
56
- systemPrompt?: string;
57
- complexity?: TextComplexity;
58
- constitutional?: boolean;
59
- agentId?: string;
60
- taskType?: string;
61
- maxTokens?: number;
62
- }
63
- export interface CallLLMResult {
64
- content: string;
65
- model: string;
66
- tier: string;
67
- cost_usd: number;
68
- }
69
- export interface HealthCheckResult {
70
- ollama: boolean;
71
- gateway: boolean;
72
- models: string[];
73
- }
74
- export interface DailyCostDigest {
75
- total_usd: number;
76
- by_tier: Record<string, number>;
77
- by_agent: Record<string, number>;
78
- tokens_saved_by_qcg: number;
79
- call_count: number;
80
- }
81
- /**
82
- * The single door every LLM call passes through (Execution Protocol §17).
83
- * Implementations: Kognai's viem-backed ClawRouter v2 (injected), a future
84
- * local-only default, or any product-specific router.
85
- */
86
- export interface ModelRouter {
87
- routeCall(req: ClawRouterV2Request): Promise<ClawRouterV2Response>;
88
- callLLM(prompt: string, opts?: CallLLMOptions): Promise<CallLLMResult>;
89
- healthCheck(): Promise<HealthCheckResult>;
90
- getDailyCostDigest(): DailyCostDigest;
91
- }
@@ -1,19 +0,0 @@
1
- "use strict";
2
- /**
3
- * model-router-contract.ts — TICKET-215 Wave C: the engine's model-routing SEAM.
4
- *
5
- * This is the zero-dep interface that decouples the orchestrator from any
6
- * concrete router. The orchestrator depends ONLY on this contract; the actual
7
- * implementation is injected at startup (see model-router-registry.ts).
8
- *
9
- * WHY: ClawRouter v2 (the production router) imports `viem` for on-chain x402
10
- * payments. We do NOT want `viem` in @kognai/orchestrator-core — that would make
11
- * every adopter (e.g. Invoica, which never routes on-chain) carry web3. So the
12
- * viem-backed router lives OUTSIDE core (Kognai injects it); products that don't
13
- * route on-chain inject their own / use a local default. viem stays absent from
14
- * core's dependency tree entirely.
15
- *
16
- * These request/response types are the canonical source of truth — clawrouter-v2
17
- * imports them from here and re-exports for back-compat.
18
- */
19
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,26 +0,0 @@
1
- /**
2
- * wallet-state.ts — CFO budget tracking for ClawRouter spend
3
- *
4
- * Accumulates spend from ClawRouter X-Payment-Amount headers.
5
- * Enforces degraded (≥80%) and frozen (≥95%) modes to protect the wallet.
6
- * Persists to logs/wallet/state.json across sprint runs.
7
- *
8
- * TICKET-215 Phase 3b-3 (Wave B): KOGNAI_ROOT now resolves via engine-paths
9
- * (KOGNAI_ROOT / cwd) instead of `resolve(__dirname, '../..')`, so the bank
10
- * state layer is location-independent and ships in @kognai/orchestrator-core.
11
- * When run from a product repo root, resolveEnginePaths().root === the old
12
- * __dirname/../.. — same <root>/logs/wallet/state.json, no behavior change.
13
- */
14
- export interface WalletState {
15
- monthlyBudget: number;
16
- spentThisMonth: number;
17
- callCount: number;
18
- remaining: number;
19
- burnPct: number;
20
- isDegraded: boolean;
21
- isFrozen: boolean;
22
- }
23
- export declare function getWalletState(): WalletState;
24
- export declare function recordSpend(costUsdc: number): void;
25
- export declare function resetWallet(): void;
26
- export declare function logWalletStatus(): void;
@@ -1,85 +0,0 @@
1
- "use strict";
2
- /**
3
- * wallet-state.ts — CFO budget tracking for ClawRouter spend
4
- *
5
- * Accumulates spend from ClawRouter X-Payment-Amount headers.
6
- * Enforces degraded (≥80%) and frozen (≥95%) modes to protect the wallet.
7
- * Persists to logs/wallet/state.json across sprint runs.
8
- *
9
- * TICKET-215 Phase 3b-3 (Wave B): KOGNAI_ROOT now resolves via engine-paths
10
- * (KOGNAI_ROOT / cwd) instead of `resolve(__dirname, '../..')`, so the bank
11
- * state layer is location-independent and ships in @kognai/orchestrator-core.
12
- * When run from a product repo root, resolveEnginePaths().root === the old
13
- * __dirname/../.. — same <root>/logs/wallet/state.json, no behavior change.
14
- */
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.getWalletState = getWalletState;
17
- exports.recordSpend = recordSpend;
18
- exports.resetWallet = resetWallet;
19
- exports.logWalletStatus = logWalletStatus;
20
- const fs_1 = require("fs");
21
- const path_1 = require("path");
22
- const engine_paths_1 = require("./engine-paths");
23
- const KOGNAI_ROOT = (0, engine_paths_1.resolveEnginePaths)().root;
24
- const STATE_FILE = (0, path_1.resolve)(KOGNAI_ROOT, 'logs/wallet/state.json');
25
- const DEFAULT_BUDGET = parseFloat(process.env.CEO_WALLET_BUDGET_USDC || '25'); // $25/month default
26
- function loadState() {
27
- if ((0, fs_1.existsSync)(STATE_FILE)) {
28
- try {
29
- const raw = JSON.parse((0, fs_1.readFileSync)(STATE_FILE, 'utf8'));
30
- // Auto-reset on new month
31
- const lastReset = new Date(raw.lastReset);
32
- const now = new Date();
33
- if (lastReset.getMonth() !== now.getMonth() || lastReset.getFullYear() !== now.getFullYear()) {
34
- return freshState();
35
- }
36
- return raw;
37
- }
38
- catch { /* fall through */ }
39
- }
40
- return freshState();
41
- }
42
- function freshState() {
43
- return {
44
- monthlyBudget: DEFAULT_BUDGET,
45
- spentThisMonth: 0,
46
- callCount: 0,
47
- lastReset: new Date().toISOString(),
48
- };
49
- }
50
- function saveState(data) {
51
- try {
52
- (0, fs_1.mkdirSync)((0, path_1.resolve)(KOGNAI_ROOT, 'logs/wallet'), { recursive: true });
53
- (0, fs_1.writeFileSync)(STATE_FILE, JSON.stringify(data, null, 2), 'utf8');
54
- }
55
- catch { /* non-fatal */ }
56
- }
57
- // Singleton
58
- let _state = loadState();
59
- function getWalletState() {
60
- const remaining = Math.max(0, _state.monthlyBudget - _state.spentThisMonth);
61
- const burnPct = (_state.spentThisMonth / _state.monthlyBudget) * 100;
62
- return {
63
- monthlyBudget: _state.monthlyBudget,
64
- spentThisMonth: _state.spentThisMonth,
65
- callCount: _state.callCount,
66
- remaining,
67
- burnPct,
68
- isDegraded: burnPct >= 80,
69
- isFrozen: burnPct >= 95,
70
- };
71
- }
72
- function recordSpend(costUsdc) {
73
- _state.spentThisMonth += costUsdc;
74
- _state.callCount += 1;
75
- saveState(_state);
76
- }
77
- function resetWallet() {
78
- _state = freshState();
79
- saveState(_state);
80
- }
81
- function logWalletStatus() {
82
- const s = getWalletState();
83
- const status = s.isFrozen ? '🔴 FROZEN' : s.isDegraded ? '🟡 DEGRADED' : '🟢 OK';
84
- console.log(` 💳 Wallet ${status}: $${s.spentThisMonth.toFixed(4)}/$${s.monthlyBudget} (${s.burnPct.toFixed(1)}%)`);
85
- }
File without changes