cognitive-kit 1.0.0-alpha.2 → 1.0.0-alpha.4

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.
@@ -0,0 +1,252 @@
1
+ export class PostgresAdapter {
2
+ config;
3
+ pool = null;
4
+ pgModule = null;
5
+ available = false;
6
+ queryCount = 0;
7
+ constructor(config) {
8
+ this.config = {
9
+ connectionString: config?.connectionString ?? process.env.KIT_PG_CONNECTION,
10
+ host: config?.host ?? process.env.KIT_PG_HOST ?? 'localhost',
11
+ port: config?.port ?? parseInt(process.env.KIT_PG_PORT ?? '5432'),
12
+ database: config?.database ?? process.env.KIT_PG_DATABASE,
13
+ user: config?.user ?? process.env.KIT_PG_USER,
14
+ password: config?.password ?? process.env.KIT_PG_PASSWORD,
15
+ maxQueries: config?.maxQueries ?? 100,
16
+ };
17
+ }
18
+ get profile() {
19
+ return {
20
+ type: 'database',
21
+ name: 'PostgreSQL Adapter',
22
+ version: '1.0.0',
23
+ capabilities: this.getCapabilities(),
24
+ metadata: {
25
+ database: this.config.database ?? '(not configured)',
26
+ host: this.config.host ?? 'localhost',
27
+ port: String(this.config.port),
28
+ available: String(this.available),
29
+ },
30
+ };
31
+ }
32
+ async initialize() {
33
+ try {
34
+ this.pgModule = await import('pg');
35
+ const cs = this.config.connectionString ||
36
+ `postgres://${this.config.user}:${this.config.password}@${this.config.host}:${this.config.port}/${this.config.database}`;
37
+ if (!cs || cs === 'postgres://undefined:undefined@localhost:5432/undefined') {
38
+ console.error('[pg-adapter] No PostgreSQL connection configured. Set KIT_PG_CONNECTION or individual env vars.');
39
+ return;
40
+ }
41
+ this.pool = new this.pgModule.Pool({ connectionString: cs, max: 5 });
42
+ const client = await this.pool.connect();
43
+ await client.query('SELECT 1');
44
+ client.release();
45
+ this.available = true;
46
+ console.error(`[pg-adapter] Connected to ${this.config.host}:${this.config.port}/${this.config.database}`);
47
+ }
48
+ catch (err) {
49
+ console.error(`[pg-adapter] Not available: ${err instanceof Error ? err.message : err}`);
50
+ this.available = false;
51
+ }
52
+ }
53
+ async shutdown() {
54
+ if (this.pool) {
55
+ await this.pool.end();
56
+ this.available = false;
57
+ }
58
+ }
59
+ getHostTools() {
60
+ if (!this.available)
61
+ return [];
62
+ return [
63
+ this.createQueryTool(),
64
+ this.createSchemaTool(),
65
+ this.createListTablesTool(),
66
+ this.createDescribeTableTool(),
67
+ ];
68
+ }
69
+ getCapabilities() {
70
+ return this.available ? ['database'] : [];
71
+ }
72
+ async query(sql, params) {
73
+ if (!this.pool)
74
+ throw new Error('Not connected');
75
+ this.queryCount++;
76
+ const result = await this.pool.query(sql, params);
77
+ return {
78
+ rows: result.rows,
79
+ rowCount: result.rowCount ?? 0,
80
+ fields: result.fields?.map((f) => f.name) ?? [],
81
+ };
82
+ }
83
+ createQueryTool() {
84
+ return {
85
+ id: 'pg_query',
86
+ name: 'PostgreSQL Query',
87
+ description: 'Execute a read-only SQL query on the connected database. Returns rows, columns, and row count.',
88
+ inputSchema: {
89
+ sql: { type: 'string', description: 'SQL query (SELECT only)' },
90
+ params: { type: 'array', description: 'Query parameter values' },
91
+ limit: { type: 'number', description: 'Maximum rows to return' },
92
+ },
93
+ sovereignty: 0.4,
94
+ category: 'host',
95
+ handler: async (params, _ctx) => {
96
+ if (!this.available)
97
+ return { success: false, data: null, error: 'PostgreSQL not connected' };
98
+ const sql = String(params.sql || '');
99
+ if (!sql)
100
+ return { success: false, data: null, error: 'SQL query is required' };
101
+ if (!/^\s*SELECT/i.test(sql.trim())) {
102
+ return { success: false, data: null, error: 'Only SELECT queries are allowed via pg_query' };
103
+ }
104
+ try {
105
+ const result = await this.query(sql, Array.isArray(params.params) ? params.params : undefined);
106
+ const limit = Number(params.limit) || 100;
107
+ const truncated = result.rows.length > limit;
108
+ return {
109
+ success: true,
110
+ data: {
111
+ columns: result.fields,
112
+ rows: result.rows.slice(0, limit),
113
+ totalRows: result.rowCount,
114
+ returnedRows: Math.min(result.rows.length, limit),
115
+ truncated,
116
+ queryCount: this.queryCount,
117
+ },
118
+ };
119
+ }
120
+ catch (err) {
121
+ return { success: false, data: null, error: `Query failed: ${err instanceof Error ? err.message : String(err)}` };
122
+ }
123
+ },
124
+ };
125
+ }
126
+ createSchemaTool() {
127
+ return {
128
+ id: 'pg_schema',
129
+ name: 'PostgreSQL Schema',
130
+ description: 'List all schemas, tables, columns, and their types in the database.',
131
+ inputSchema: { schema: { type: 'string', description: 'Filter by schema name (default: public)' } },
132
+ category: 'host',
133
+ handler: async (params, _ctx) => {
134
+ if (!this.available)
135
+ return { success: false, data: null, error: 'PostgreSQL not connected' };
136
+ const schemaFilter = String(params.schema || 'public');
137
+ try {
138
+ const result = await this.query(`
139
+ SELECT
140
+ t.table_schema, t.table_name, c.column_name, c.data_type,
141
+ c.is_nullable, c.character_maximum_length,
142
+ (SELECT json_agg(indexname) FROM pg_indexes WHERE tablename = t.table_name AND schemaname = t.table_schema) as indexes
143
+ FROM information_schema.tables t
144
+ JOIN information_schema.columns c ON t.table_schema = c.table_schema AND t.table_name = c.table_name
145
+ WHERE t.table_schema = $1 AND t.table_type = 'BASE TABLE'
146
+ ORDER BY t.table_name, c.ordinal_position
147
+ `, [schemaFilter]);
148
+ const tables = new Map();
149
+ for (const row of result.rows) {
150
+ const key = `${row.table_schema}.${row.table_name}`;
151
+ if (!tables.has(key))
152
+ tables.set(key, []);
153
+ tables.get(key).push({
154
+ name: row.column_name, type: row.data_type,
155
+ nullable: row.is_nullable === 'YES',
156
+ maxLength: row.character_maximum_length,
157
+ });
158
+ }
159
+ return {
160
+ success: true,
161
+ data: {
162
+ schema: schemaFilter,
163
+ tables: Array.from(tables.entries()).map(([name, columns]) => ({ name, columns, columnCount: columns.length })),
164
+ totalTables: tables.size,
165
+ },
166
+ };
167
+ }
168
+ catch (err) {
169
+ return { success: false, data: null, error: `Schema query failed: ${err instanceof Error ? err.message : String(err)}` };
170
+ }
171
+ },
172
+ };
173
+ }
174
+ createListTablesTool() {
175
+ return {
176
+ id: 'pg_list_tables',
177
+ name: 'PostgreSQL List Tables',
178
+ description: 'List all tables in the database with row counts and sizes.',
179
+ inputSchema: { schema: { type: 'string', description: 'Schema filter (default: public)' } },
180
+ category: 'host',
181
+ handler: async (params, _ctx) => {
182
+ if (!this.available)
183
+ return { success: false, data: null, error: 'PostgreSQL not connected' };
184
+ const schema = String(params.schema || 'public');
185
+ try {
186
+ const result = await this.query(`
187
+ SELECT
188
+ relname as table_name,
189
+ n_live_tup as estimated_rows,
190
+ pg_size_pretty(pg_total_relation_size(relid)) as total_size
191
+ FROM pg_stat_user_tables
192
+ WHERE schemaname = $1
193
+ ORDER BY relname
194
+ `, [schema]);
195
+ return {
196
+ success: true,
197
+ data: { schema, tables: result.rows, total: result.rows.length },
198
+ };
199
+ }
200
+ catch (err) {
201
+ return { success: false, data: null, error: `Failed to list tables: ${err instanceof Error ? err.message : String(err)}` };
202
+ }
203
+ },
204
+ };
205
+ }
206
+ createDescribeTableTool() {
207
+ return {
208
+ id: 'pg_describe',
209
+ name: 'PostgreSQL Describe Table',
210
+ description: 'Get detailed info about a specific table including columns, constraints, and indexes.',
211
+ inputSchema: {
212
+ table: { type: 'string', description: 'Table name' },
213
+ schema: { type: 'string', description: 'Schema (default: public)' },
214
+ },
215
+ category: 'host',
216
+ handler: async (params, _ctx) => {
217
+ if (!this.available)
218
+ return { success: false, data: null, error: 'PostgreSQL not connected' };
219
+ const table = String(params.table || '');
220
+ const schema = String(params.schema || 'public');
221
+ if (!table)
222
+ return { success: false, data: null, error: 'table name is required' };
223
+ try {
224
+ const [columns, indexes, sample] = await Promise.all([
225
+ this.query(`
226
+ SELECT column_name, data_type, is_nullable, column_default, character_maximum_length
227
+ FROM information_schema.columns
228
+ WHERE table_schema = $1 AND table_name = $2
229
+ ORDER BY ordinal_position
230
+ `, [schema, table]),
231
+ this.query(`SELECT indexname, indexdef FROM pg_indexes WHERE schemaname = $1 AND tablename = $2`, [schema, table]),
232
+ this.query(`SELECT * FROM "${schema}"."${table}" LIMIT 5`),
233
+ ]);
234
+ return {
235
+ success: true,
236
+ data: {
237
+ table: `${schema}.${table}`,
238
+ columns: columns.rows,
239
+ indexes: indexes.rows,
240
+ sampleData: sample.rows,
241
+ sampleCount: sample.rows.length,
242
+ },
243
+ };
244
+ }
245
+ catch (err) {
246
+ return { success: false, data: null, error: `Failed to describe table: ${err instanceof Error ? err.message : String(err)}` };
247
+ }
248
+ },
249
+ };
250
+ }
251
+ }
252
+ //# sourceMappingURL=PostgresAdapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PostgresAdapter.js","sourceRoot":"","sources":["../../../src/host/adapters/PostgresAdapter.ts"],"names":[],"mappings":"AAaA,MAAM,OAAO,eAAe;IAClB,MAAM,CAAiB;IACvB,IAAI,GAAQ,IAAI,CAAC;IACjB,QAAQ,GAAQ,IAAI,CAAC;IACrB,SAAS,GAAG,KAAK,CAAC;IAClB,UAAU,GAAG,CAAC,CAAC;IAEvB,YAAY,MAAuB;QACjC,IAAI,CAAC,MAAM,GAAG;YACZ,gBAAgB,EAAE,MAAM,EAAE,gBAAgB,IAAI,OAAO,CAAC,GAAG,CAAC,iBAAiB;YAC3E,IAAI,EAAE,MAAM,EAAE,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,WAAW;YAC5D,IAAI,EAAE,MAAM,EAAE,IAAI,IAAI,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,MAAM,CAAC;YACjE,QAAQ,EAAE,MAAM,EAAE,QAAQ,IAAI,OAAO,CAAC,GAAG,CAAC,eAAe;YACzD,IAAI,EAAE,MAAM,EAAE,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC,WAAW;YAC7C,QAAQ,EAAE,MAAM,EAAE,QAAQ,IAAI,OAAO,CAAC,GAAG,CAAC,eAAe;YACzD,UAAU,EAAE,MAAM,EAAE,UAAU,IAAI,GAAG;SACtC,CAAC;IACJ,CAAC;IAED,IAAI,OAAO;QACT,OAAO;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;wBACnD,IAAI,CAAC,KAAK,CAAC;;;;;aAKV,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;wBACnB,IAAI,CAAC,KAAK,CAAC,qFAAqF,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;wBAClH,IAAI,CAAC,KAAK,CAAC,kBAAkB,MAAM,MAAM,KAAK,WAAW,CAAC;qBAC3D,CAAC,CAAC;oBACH,OAAO;wBACL,OAAO,EAAE,IAAI;wBACb,IAAI,EAAE;4BACJ,KAAK,EAAE,GAAG,MAAM,IAAI,KAAK,EAAE;4BAC3B,OAAO,EAAE,OAAO,CAAC,IAAI;4BACrB,OAAO,EAAE,OAAO,CAAC,IAAI;4BACrB,UAAU,EAAE,MAAM,CAAC,IAAI;4BACvB,WAAW,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM;yBAChC;qBACF,CAAC;gBACJ,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACb,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,6BAA6B,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;gBAChI,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF"}
package/dist/index.d.ts CHANGED
@@ -13,6 +13,8 @@ export { DirectTransport } from './mcp/transports/DirectTransport.js';
13
13
  export type { Transport } from './mcp/transports/Transport.js';
14
14
  export type { HostAdapter } from './host/HostAdapter.js';
15
15
  export { VSCodeAdapter } from './host/adapters/VSCodeAdapter.js';
16
+ export { FileSystemAdapter } from './host/adapters/FileSystemAdapter.js';
17
+ export { PostgresAdapter } from './host/adapters/PostgresAdapter.js';
16
18
  export { SkillRegistry } from './skills/SkillRegistry.js';
17
19
  export { AgencyRegistry } from './agencies/AgencyRegistry.js';
18
20
  export { AgencyOrchestrator } from './agencies/AgencyOrchestrator.js';
package/dist/index.js CHANGED
@@ -15,6 +15,8 @@ export { StdioTransport } from './mcp/transports/StdioTransport.js';
15
15
  export { SSETransport } from './mcp/transports/SSETransport.js';
16
16
  export { DirectTransport } from './mcp/transports/DirectTransport.js';
17
17
  export { VSCodeAdapter } from './host/adapters/VSCodeAdapter.js';
18
+ export { FileSystemAdapter } from './host/adapters/FileSystemAdapter.js';
19
+ export { PostgresAdapter } from './host/adapters/PostgresAdapter.js';
18
20
  // Skills
19
21
  export { SkillRegistry } from './skills/SkillRegistry.js';
20
22
  // Agencies
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO;AACP,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC,SAAS;AACT,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAExE,WAAW;AACX,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAEhE,SAAS;AACT,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAC;AAC1E,OAAO,EAAE,cAAc,EAAE,MAAM,sCAAsC,CAAC;AAEtE,MAAM;AACN,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAKtE,OAAO,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AAEjE,SAAS;AACT,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE1D,WAAW;AACX,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B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AAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAKtE,OAAO,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AACzE,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAErE,SAAS;AACT,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE1D,WAAW;AACX,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAEtE,WAAW;AACX,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAE5D,QAAQ;AACR,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEzD,aAAa;AACb,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAEpE,4BAA4B;AAC5B,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,79 @@
1
+ # Example: Custom Host Adapter
2
+
3
+ Create a custom adapter to integrate Cognitive Kit with any system.
4
+
5
+ ```typescript
6
+ import { CognitiveKit, type HostAdapter, type HostProfile, type ToolDefinition, type ToolResult, type ToolContext, type HostCapability } from 'cognitive-kit';
7
+
8
+ class MyAPIAdapter implements HostAdapter {
9
+ private apiKey: string;
10
+ private baseUrl: string;
11
+
12
+ constructor(apiKey: string, baseUrl: string) {
13
+ this.apiKey = apiKey;
14
+ this.baseUrl = baseUrl;
15
+ }
16
+
17
+ get profile(): HostProfile {
18
+ return {
19
+ type: 'api',
20
+ name: 'My API Adapter',
21
+ version: '1.0.0',
22
+ capabilities: this.getCapabilities(),
23
+ metadata: { baseUrl: this.baseUrl },
24
+ };
25
+ }
26
+
27
+ async initialize(): Promise<void> {
28
+ console.error(`[my-adapter] Connected to ${this.baseUrl}`);
29
+ }
30
+
31
+ async shutdown(): Promise<void> {
32
+ console.error('[my-adapter] Disconnected');
33
+ }
34
+
35
+ getHostTools(): ToolDefinition[] {
36
+ return [
37
+ {
38
+ id: 'my_api_call',
39
+ name: 'My API Call',
40
+ description: 'Call an endpoint on My API',
41
+ inputSchema: {
42
+ endpoint: { type: 'string' },
43
+ method: { type: 'string', enum: ['GET', 'POST'] },
44
+ body: { type: 'object' },
45
+ },
46
+ category: 'host',
47
+ handler: async (params: Record<string, unknown>, _ctx: ToolContext): Promise<ToolResult> => {
48
+ const endpoint = String(params.endpoint || '');
49
+ const method = String(params.method || 'GET');
50
+ try {
51
+ const response = await fetch(`${this.baseUrl}${endpoint}`, {
52
+ method,
53
+ headers: { Authorization: `Bearer ${this.apiKey}`, 'Content-Type': 'application/json' },
54
+ body: method === 'POST' ? JSON.stringify(params.body || {}) : undefined,
55
+ });
56
+ const data = await response.json();
57
+ return { success: response.ok, data, error: response.ok ? undefined : data.error };
58
+ } catch (err) {
59
+ return { success: false, data: null, error: `API call failed: ${err instanceof Error ? err.message : String(err)}` };
60
+ }
61
+ },
62
+ },
63
+ ];
64
+ }
65
+
66
+ getCapabilities(): HostCapability[] {
67
+ return ['network'];
68
+ }
69
+ }
70
+
71
+ // Use it
72
+ const kit = new CognitiveKit({
73
+ host: new MyAPIAdapter('sk-...', 'https://api.example.com'),
74
+ transport: { type: 'stdio' },
75
+ });
76
+
77
+ await kit.start();
78
+ // Now has all cognitive tools + my_api_call
79
+ ```
@@ -0,0 +1,60 @@
1
+ # Example: Multi-Kit Federation
2
+
3
+ Connect multiple Cognitive Kit instances. Kit in VS Code, Kit in Database, Kit in CI — all federated.
4
+
5
+ ```typescript
6
+ // Kit A: Server (database side)
7
+ import { CognitiveKit, PostgresAdapter } from 'cognitive-kit';
8
+
9
+ const kitA = new CognitiveKit({
10
+ host: new PostgresAdapter({ connectionString: 'postgres://...' }),
11
+ storage: { type: 'sqlite', path: './kit-a.db' },
12
+ transport: { type: 'sse', port: 3100 },
13
+ });
14
+
15
+ await kitA.start();
16
+ // Federation server listening on port 3100
17
+ ```
18
+
19
+ ```typescript
20
+ // Kit B: Client (VS Code side)
21
+ import { CognitiveKit, FileSystemAdapter } from 'cognitive-kit';
22
+
23
+ const kitB = new CognitiveKit({
24
+ host: new FileSystemAdapter('./project'),
25
+ transport: { type: 'direct' },
26
+ });
27
+
28
+ await kitB.initialize();
29
+
30
+ // Connect to Kit A
31
+ await kitB.federationManager.connectTo('http://localhost:3100');
32
+
33
+ // Execute database tools remotely
34
+ const tables = await kitB.federationManager.executeOnPeer(
35
+ 'http://localhost:3100',
36
+ 'pg_list_tables',
37
+ {}
38
+ );
39
+ console.log(tables.data);
40
+
41
+ // Use Kit A's cognitive tools + Kit B's filesystem tools together
42
+ const analysis = await kitB.federationManager.executeOnPeer(
43
+ 'http://localhost:3100',
44
+ 'knowledge_evolve',
45
+ { knowledgeBase: JSON.stringify(tables), mode: 'gap' }
46
+ );
47
+ console.log(analysis.data);
48
+
49
+ await kitB.stop();
50
+ ```
51
+
52
+ ## Federation Protocol
53
+
54
+ ```
55
+ Kit A (SSE:4200) ←→ Kit B (stdio) ←→ Kit C (SSE:4201)
56
+ ↑ ↑
57
+ PostgreSQL Filesystem
58
+ ```
59
+
60
+ Each kit exposes its tools via the federation protocol. Kits discover each other's tools and call them remotely with sovereignty delegation.
@@ -0,0 +1,69 @@
1
+ # Example: Library Embedding
2
+
3
+ Embed Cognitive Kit directly into your Node.js application.
4
+
5
+ ```typescript
6
+ import { CognitiveKit, FileSystemAdapter } from 'cognitive-kit';
7
+
8
+ async function main() {
9
+ // Create kit with filesystem adapter
10
+ const kit = new CognitiveKit({
11
+ host: new FileSystemAdapter('./workspace', { allowWrite: true }),
12
+ storage: { type: 'sqlite', path: './.cognitive-kit.db' },
13
+ transport: { type: 'direct' }, // in-process, no stdio
14
+ sovereignty: {
15
+ hostId: 'my-app',
16
+ hostName: 'My Application',
17
+ },
18
+ });
19
+
20
+ await kit.initialize();
21
+
22
+ console.log(`Tools: ${kit.toolCount}`);
23
+ console.log(`Skills: ${kit.skillCount}`);
24
+ console.log(`Identity: ${kit.identityInfo}`);
25
+
26
+ // Register a custom tool
27
+ kit.registerTool({
28
+ id: 'my_tool',
29
+ name: 'My Custom Tool',
30
+ description: 'App-specific tool',
31
+ inputSchema: { input: { type: 'string' } },
32
+ category: 'cognitive',
33
+ handler: async (params, ctx) => ({
34
+ success: true,
35
+ data: { processed: `Hello ${params.input || 'world'}` },
36
+ metadata: { sovereignty: ctx.identity.sovereignty },
37
+ }),
38
+ });
39
+
40
+ // Execute built-in tools via the tool registry
41
+ const context = {
42
+ identity: { actorId: 'user', actorType: 'user', sovereignty: 0.9, permissions: ['execute'] },
43
+ host: { type: 'cli', name: 'app', capabilities: [] },
44
+ memory: kit['memory'],
45
+ };
46
+
47
+ const reason = await kit['toolRegistry'].execute('cognitive_reason', {
48
+ problem: 'Design a microservices architecture',
49
+ mode: 'logical',
50
+ }, context);
51
+
52
+ console.log(reason.data?.conclusion);
53
+
54
+ // Run an agency mission
55
+ const mission = await kit.executeAgency(
56
+ 'Analyze system performance',
57
+ { mode: 'sequential' }
58
+ );
59
+ console.log(`Mission: ${mission.status} (${mission.synergyScore})`);
60
+
61
+ // Forge skills from usage
62
+ const skills = kit.forge.forgeFromPatterns(true);
63
+ console.log(`Forged ${skills.length} new skills`);
64
+
65
+ await kit.stop();
66
+ }
67
+
68
+ main().catch(console.error);
69
+ ```
@@ -0,0 +1,48 @@
1
+ # Example: MCP Server (standalone)
2
+
3
+ Run Cognitive Kit as a standalone MCP server for any client (VS Code, Cursor, Claude Desktop, or custom).
4
+
5
+ ```typescript
6
+ // mcp-server.ts
7
+ import { CognitiveKit } from 'cognitive-kit';
8
+
9
+ const kit = new CognitiveKit({
10
+ host: {
11
+ type: 'cli',
12
+ name: 'My MCP Server',
13
+ capabilities: ['filesystem'],
14
+ },
15
+ storage: { type: 'sqlite', path: './.kit.db' },
16
+ transport: { type: 'stdio' },
17
+ sovereignty: {
18
+ hostId: process.env.KIT_HOST_ID || 'mcp-1',
19
+ hostName: process.env.KIT_HOST_NAME || 'MCP Server',
20
+ },
21
+ });
22
+
23
+ process.on('SIGINT', async () => { await kit.stop(); process.exit(0); });
24
+ process.on('SIGTERM', async () => { await kit.stop(); process.exit(0); });
25
+
26
+ await kit.start();
27
+ // MCP protocol on stdio — 31 tools available
28
+ ```
29
+
30
+ ## Run
31
+
32
+ ```bash
33
+ npx tsx mcp-server.ts
34
+ ```
35
+
36
+ ## Add to VS Code
37
+
38
+ ```json
39
+ {
40
+ "servers": {
41
+ "cognitive-kit": {
42
+ "type": "stdio",
43
+ "command": "npx",
44
+ "args": ["tsx", "/path/to/mcp-server.ts"]
45
+ }
46
+ }
47
+ }
48
+ ```
@@ -0,0 +1,48 @@
1
+ # Example: PostgreSQL Knowledge Explorer
2
+
3
+ Use Cognitive Kit + PostgreSQL adapter to explore, analyze, and document your database.
4
+
5
+ ```typescript
6
+ import { CognitiveKit, PostgresAdapter } from 'cognitive-kit';
7
+
8
+ const kit = new CognitiveKit({
9
+ host: new PostgresAdapter({
10
+ connectionString: process.env.DATABASE_URL,
11
+ }),
12
+ storage: { type: 'memory' },
13
+ transport: { type: 'direct' },
14
+ sovereignty: { hostId: 'pg-explorer', hostName: 'DB Explorer' },
15
+ });
16
+
17
+ await kit.initialize();
18
+
19
+ const ctx = {
20
+ identity: { actorId: 'admin', actorType: 'host', sovereignty: 1.0, permissions: ['read', 'execute'] },
21
+ host: { type: 'database', name: 'pg', capabilities: ['database'] },
22
+ memory: kit['memory'],
23
+ };
24
+
25
+ // 1. Explore the schema
26
+ const schema = await kit['toolRegistry'].execute('pg_schema', { schema: 'public' }, ctx);
27
+ console.log(`Tables: ${schema.data.totalTables}`);
28
+
29
+ // 2. Research each table
30
+ for (const table of schema.data.tables) {
31
+ const analysis = await kit['toolRegistry'].execute('cognitive_reason', {
32
+ problem: `Analyze the ${table.name} table structure`,
33
+ context: JSON.stringify(table.columns),
34
+ mode: 'logical',
35
+ }, ctx);
36
+ console.log(`${table.name}: ${analysis.data?.conclusion}`);
37
+ }
38
+
39
+ // 3. Generate documentation
40
+ const doc = await kit['toolRegistry'].execute('cognitive_plan', {
41
+ objective: 'Document all database schemas',
42
+ context: JSON.stringify(schema.data),
43
+ }, ctx);
44
+
45
+ console.log(doc.data?.pipeline);
46
+
47
+ await kit.stop();
48
+ ```