@thispointon/kondi-chat 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +556 -0
- package/bin/kondi-chat +56 -0
- package/bin/kondi-chat.js +72 -0
- package/package.json +55 -0
- package/scripts/demo.tape +49 -0
- package/scripts/postinstall.cjs +103 -0
- package/src/audit/analytics.ts +261 -0
- package/src/audit/ledger.ts +253 -0
- package/src/audit/telemetry.ts +165 -0
- package/src/cli/backend.ts +675 -0
- package/src/cli/commands.ts +419 -0
- package/src/cli/help.ts +182 -0
- package/src/cli/submit-helpers.ts +159 -0
- package/src/cli/submit.ts +539 -0
- package/src/cli/wizard.ts +121 -0
- package/src/context/bootstrap.ts +138 -0
- package/src/context/budget.ts +100 -0
- package/src/context/manager.ts +666 -0
- package/src/context/memory.ts +160 -0
- package/src/context/preflight.ts +176 -0
- package/src/context/project-brain.ts +101 -0
- package/src/context/receipts.ts +108 -0
- package/src/context/skills.ts +154 -0
- package/src/context/symbol-index.ts +240 -0
- package/src/council/profiles.ts +137 -0
- package/src/council/tool.ts +138 -0
- package/src/council-engine/cli/council-artifacts.ts +230 -0
- package/src/council-engine/cli/council-config.ts +178 -0
- package/src/council-engine/cli/council-session-export.ts +116 -0
- package/src/council-engine/cli/kondi.ts +98 -0
- package/src/council-engine/cli/llm-caller.ts +229 -0
- package/src/council-engine/cli/localStorage-shim.ts +119 -0
- package/src/council-engine/cli/node-platform.ts +68 -0
- package/src/council-engine/cli/run-council.ts +481 -0
- package/src/council-engine/cli/run-pipeline.ts +772 -0
- package/src/council-engine/cli/session-export.ts +153 -0
- package/src/council-engine/configs/councils/analysis.json +101 -0
- package/src/council-engine/configs/councils/code-planning.json +86 -0
- package/src/council-engine/configs/councils/coding.json +89 -0
- package/src/council-engine/configs/councils/debate.json +97 -0
- package/src/council-engine/configs/councils/solo-claude.json +34 -0
- package/src/council-engine/configs/councils/solo-gpt.json +34 -0
- package/src/council-engine/council/coding-orchestrator.ts +1205 -0
- package/src/council-engine/council/context-bootstrap.ts +147 -0
- package/src/council-engine/council/context-inspection.ts +42 -0
- package/src/council-engine/council/context-store.ts +763 -0
- package/src/council-engine/council/deliberation-orchestrator.ts +2762 -0
- package/src/council-engine/council/factory.ts +164 -0
- package/src/council-engine/council/index.ts +201 -0
- package/src/council-engine/council/ledger-store.ts +438 -0
- package/src/council-engine/council/prompts.ts +1689 -0
- package/src/council-engine/council/storage-cleanup.ts +164 -0
- package/src/council-engine/council/store.ts +1110 -0
- package/src/council-engine/council/synthesis.ts +291 -0
- package/src/council-engine/council/types.ts +845 -0
- package/src/council-engine/council/validation.ts +613 -0
- package/src/council-engine/pipeline/build-detect.ts +73 -0
- package/src/council-engine/pipeline/executor.ts +1048 -0
- package/src/council-engine/pipeline/index.ts +9 -0
- package/src/council-engine/pipeline/install-detect.ts +84 -0
- package/src/council-engine/pipeline/memory-store.ts +182 -0
- package/src/council-engine/pipeline/output-parsers.ts +146 -0
- package/src/council-engine/pipeline/run-output.ts +149 -0
- package/src/council-engine/pipeline/session-import.ts +177 -0
- package/src/council-engine/pipeline/store.ts +753 -0
- package/src/council-engine/pipeline/test-detect.ts +82 -0
- package/src/council-engine/pipeline/types.ts +401 -0
- package/src/council-engine/services/deliberationSummary.ts +114 -0
- package/src/council-engine/tsconfig.json +16 -0
- package/src/council-engine/types/mcp.ts +122 -0
- package/src/council-engine/utils/filterTools.ts +73 -0
- package/src/engine/apply.ts +238 -0
- package/src/engine/checkpoints.ts +237 -0
- package/src/engine/consultants.ts +347 -0
- package/src/engine/diff.ts +171 -0
- package/src/engine/errors.ts +102 -0
- package/src/engine/git-tools.ts +246 -0
- package/src/engine/hooks.ts +181 -0
- package/src/engine/loop-guard.ts +155 -0
- package/src/engine/permissions.ts +293 -0
- package/src/engine/pipeline.ts +376 -0
- package/src/engine/sub-agents.ts +133 -0
- package/src/engine/task-card.ts +185 -0
- package/src/engine/task-router.ts +256 -0
- package/src/engine/task-store.ts +86 -0
- package/src/engine/tools.ts +783 -0
- package/src/engine/verify.ts +111 -0
- package/src/mcp/client.ts +225 -0
- package/src/mcp/config.ts +120 -0
- package/src/mcp/tool-manager.ts +192 -0
- package/src/mcp/types.ts +61 -0
- package/src/providers/llm-caller.ts +943 -0
- package/src/providers/rate-limiter.ts +238 -0
- package/src/router/NOTES.md +28 -0
- package/src/router/collector.ts +474 -0
- package/src/router/embeddings.ts +286 -0
- package/src/router/index.ts +299 -0
- package/src/router/intent-router.ts +225 -0
- package/src/router/nn-router.ts +205 -0
- package/src/router/profiles.ts +309 -0
- package/src/router/registry.ts +565 -0
- package/src/router/rules.ts +274 -0
- package/src/router/train.py +408 -0
- package/src/session/store.ts +211 -0
- package/src/test-utils/mock-llm.ts +39 -0
- package/src/types.ts +322 -0
- package/src/web/manager.ts +311 -0
|
@@ -0,0 +1,613 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Council: Validation Schemas
|
|
3
|
+
* Zod schemas for validating Council configurations
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
|
|
8
|
+
// ============================================================================
|
|
9
|
+
// Basic Schemas
|
|
10
|
+
// ============================================================================
|
|
11
|
+
|
|
12
|
+
export const stanceSchema = z.enum(['advocate', 'critic', 'neutral', 'wildcard']);
|
|
13
|
+
|
|
14
|
+
export const interactionStyleSchema = z.enum(['debate', 'build', 'question', 'synthesize', 'review']);
|
|
15
|
+
|
|
16
|
+
export const councilModeSchema = z.enum([
|
|
17
|
+
'debate',
|
|
18
|
+
'build',
|
|
19
|
+
'review',
|
|
20
|
+
'synthesis',
|
|
21
|
+
'socratic',
|
|
22
|
+
'freeform',
|
|
23
|
+
'deliberation',
|
|
24
|
+
]);
|
|
25
|
+
|
|
26
|
+
export const turnStrategySchema = z.enum([
|
|
27
|
+
'round-robin',
|
|
28
|
+
'react',
|
|
29
|
+
'popcorn',
|
|
30
|
+
'volunteer',
|
|
31
|
+
'moderator',
|
|
32
|
+
'parallel',
|
|
33
|
+
'relevance',
|
|
34
|
+
]);
|
|
35
|
+
|
|
36
|
+
export const verbositySchema = z.enum(['concise', 'balanced', 'thorough']);
|
|
37
|
+
|
|
38
|
+
export const speakerTypeSchema = z.enum(['persona', 'user', 'system']);
|
|
39
|
+
|
|
40
|
+
export const sentimentSchema = z.enum(['agree', 'disagree', 'partial', 'neutral', 'question']);
|
|
41
|
+
|
|
42
|
+
export const claimTypeSchema = z.enum(['assertion', 'question', 'proposal', 'objection']);
|
|
43
|
+
|
|
44
|
+
export const councilStatusSchema = z.enum(['active', 'paused', 'resolved']);
|
|
45
|
+
|
|
46
|
+
export const documentTypeSchema = z.enum(['text', 'pdf', 'image', 'data']);
|
|
47
|
+
|
|
48
|
+
// ============================================================================
|
|
49
|
+
// Predisposition Schema
|
|
50
|
+
// ============================================================================
|
|
51
|
+
|
|
52
|
+
export const predispositionSchema = z.object({
|
|
53
|
+
systemPrompt: z.string().min(10, 'System prompt must be at least 10 characters'),
|
|
54
|
+
stance: stanceSchema,
|
|
55
|
+
arguesFor: z.string().optional(),
|
|
56
|
+
arguesAgainst: z.string().optional(),
|
|
57
|
+
traits: z.array(z.string()).min(1, 'At least one trait required'),
|
|
58
|
+
interactionStyle: interactionStyleSchema,
|
|
59
|
+
domain: z.string().optional(),
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// ============================================================================
|
|
63
|
+
// Persona Schema
|
|
64
|
+
// ============================================================================
|
|
65
|
+
|
|
66
|
+
export const deliberationRoleSchema = z.enum(['manager', 'consultant', 'worker', 'reviewer']);
|
|
67
|
+
|
|
68
|
+
export const personaSchema = z.object({
|
|
69
|
+
id: z.string().uuid(),
|
|
70
|
+
name: z.string().min(1, 'Name is required').max(50, 'Name too long'),
|
|
71
|
+
provider: z.string().min(1, 'Provider is required'),
|
|
72
|
+
model: z.string().min(1, 'Model is required'),
|
|
73
|
+
predisposition: predispositionSchema,
|
|
74
|
+
avatar: z.string().optional(),
|
|
75
|
+
color: z.string().regex(/^#[0-9A-Fa-f]{6}$/, 'Invalid hex color'),
|
|
76
|
+
temperature: z.number().min(0).max(1).optional(),
|
|
77
|
+
verbosity: verbositySchema,
|
|
78
|
+
muted: z.boolean().optional(),
|
|
79
|
+
preferredDeliberationRole: deliberationRoleSchema.optional(),
|
|
80
|
+
allowedServerIds: z.array(z.string()).optional(),
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
export const presetPersonaSchema = z.object({
|
|
84
|
+
name: z.string().min(1),
|
|
85
|
+
defaultProvider: z.string().min(1),
|
|
86
|
+
defaultModel: z.string().min(1),
|
|
87
|
+
color: z.string().regex(/^#[0-9A-Fa-f]{6}$/),
|
|
88
|
+
avatar: z.string().optional(),
|
|
89
|
+
temperature: z.number().min(0).max(1).optional(),
|
|
90
|
+
verbosity: verbositySchema.optional(),
|
|
91
|
+
predisposition: predispositionSchema,
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// ============================================================================
|
|
95
|
+
// Document & Context Schemas
|
|
96
|
+
// ============================================================================
|
|
97
|
+
|
|
98
|
+
export const documentSchema = z.object({
|
|
99
|
+
id: z.string().uuid(),
|
|
100
|
+
name: z.string().min(1),
|
|
101
|
+
type: documentTypeSchema,
|
|
102
|
+
content: z.string(),
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
export const sharedContextSchema = z.object({
|
|
106
|
+
description: z.string().min(1, 'Description is required'),
|
|
107
|
+
documents: z.array(documentSchema).default([]),
|
|
108
|
+
data: z.record(z.string(), z.unknown()).optional(),
|
|
109
|
+
constraints: z.array(z.string()).optional(),
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
// ============================================================================
|
|
113
|
+
// Orchestration Schema
|
|
114
|
+
// ============================================================================
|
|
115
|
+
|
|
116
|
+
export const orchestrationConfigSchema = z.object({
|
|
117
|
+
mode: councilModeSchema,
|
|
118
|
+
turnStrategy: turnStrategySchema,
|
|
119
|
+
maxTurnsPerRound: z.number().int().min(1).max(20).default(5),
|
|
120
|
+
maxTotalTurns: z.number().int().min(1).max(100).optional(),
|
|
121
|
+
autoSynthesize: z.boolean().default(true),
|
|
122
|
+
synthesizerId: z.string().optional(),
|
|
123
|
+
convergenceCriteria: z.string().optional(),
|
|
124
|
+
requiresResolution: z.boolean().default(false),
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
// ============================================================================
|
|
128
|
+
// Message Schemas
|
|
129
|
+
// ============================================================================
|
|
130
|
+
|
|
131
|
+
export const claimSchema = z.object({
|
|
132
|
+
id: z.string().uuid(),
|
|
133
|
+
text: z.string().min(1),
|
|
134
|
+
type: claimTypeSchema,
|
|
135
|
+
supportedBy: z.array(z.string().uuid()).optional(),
|
|
136
|
+
opposedBy: z.array(z.string().uuid()).optional(),
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
export const councilMessageSchema = z.object({
|
|
140
|
+
id: z.string().uuid(),
|
|
141
|
+
timestamp: z.string().datetime(),
|
|
142
|
+
speakerId: z.string(),
|
|
143
|
+
speakerType: speakerTypeSchema,
|
|
144
|
+
content: z.string().min(1),
|
|
145
|
+
replyingTo: z.string().uuid().optional(),
|
|
146
|
+
threadId: z.string().uuid().optional(),
|
|
147
|
+
sentiment: sentimentSchema.optional(),
|
|
148
|
+
stance: z.string().optional(),
|
|
149
|
+
confidence: z.number().min(0).max(1).optional(),
|
|
150
|
+
claims: z.array(claimSchema).optional(),
|
|
151
|
+
tokensUsed: z.number().int().min(0),
|
|
152
|
+
latencyMs: z.number().int().min(0),
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
// ============================================================================
|
|
156
|
+
// Resolution Schema
|
|
157
|
+
// ============================================================================
|
|
158
|
+
|
|
159
|
+
export const resolutionSchema = z.object({
|
|
160
|
+
summary: z.string().min(10),
|
|
161
|
+
consensusLevel: z.number().min(0).max(1),
|
|
162
|
+
keyDecisions: z.array(z.string()),
|
|
163
|
+
agreements: z.array(z.string()).optional(),
|
|
164
|
+
tensions: z.array(z.string()).optional(),
|
|
165
|
+
dissent: z.array(z.string()).optional(),
|
|
166
|
+
nextSteps: z.array(z.string()).optional(),
|
|
167
|
+
generatedBy: z.string(),
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
// ============================================================================
|
|
171
|
+
// Council Schema
|
|
172
|
+
// ============================================================================
|
|
173
|
+
|
|
174
|
+
export const councilSchema = z.object({
|
|
175
|
+
id: z.string().uuid(),
|
|
176
|
+
name: z.string().min(1).max(100),
|
|
177
|
+
createdAt: z.string().datetime(),
|
|
178
|
+
updatedAt: z.string().datetime(),
|
|
179
|
+
topic: z.string().min(1),
|
|
180
|
+
sharedContext: sharedContextSchema,
|
|
181
|
+
personas: z.array(personaSchema).min(1, 'At least 1 persona required'),
|
|
182
|
+
orchestration: orchestrationConfigSchema,
|
|
183
|
+
messages: z.array(councilMessageSchema).default([]),
|
|
184
|
+
status: councilStatusSchema,
|
|
185
|
+
resolution: resolutionSchema.optional(),
|
|
186
|
+
totalTokensUsed: z.number().int().min(0).default(0),
|
|
187
|
+
estimatedCost: z.number().min(0).default(0),
|
|
188
|
+
// Deliberation fields (optional, only when mode === 'deliberation')
|
|
189
|
+
deliberation: z.lazy(() => deliberationConfigSchema).optional(),
|
|
190
|
+
deliberationState: z.lazy(() => deliberationStateSchema).optional(),
|
|
191
|
+
// Pipeline linkage (set when council was created by a pipeline step)
|
|
192
|
+
pipelineId: z.string().optional(),
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
// ============================================================================
|
|
196
|
+
// Request Schemas
|
|
197
|
+
// ============================================================================
|
|
198
|
+
|
|
199
|
+
export const createCouncilRequestSchema = z.object({
|
|
200
|
+
name: z.string().min(1).max(100),
|
|
201
|
+
topic: z.string().min(5),
|
|
202
|
+
sharedContext: sharedContextSchema.partial().optional(),
|
|
203
|
+
personas: z.array(
|
|
204
|
+
z.object({
|
|
205
|
+
templateId: z.string().optional(),
|
|
206
|
+
}).merge(personaSchema.partial())
|
|
207
|
+
).optional(),
|
|
208
|
+
orchestration: orchestrationConfigSchema.partial().optional(),
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
export const addPersonaRequestSchema = z.object({
|
|
212
|
+
templateId: z.string().optional(),
|
|
213
|
+
persona: personaSchema.partial().optional(),
|
|
214
|
+
}).refine(
|
|
215
|
+
(data) => data.templateId || data.persona,
|
|
216
|
+
'Either templateId or persona must be provided'
|
|
217
|
+
);
|
|
218
|
+
|
|
219
|
+
export const sendMessageRequestSchema = z.object({
|
|
220
|
+
content: z.string().min(1),
|
|
221
|
+
replyingTo: z.string().uuid().optional(),
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
export const askPersonaRequestSchema = z.object({
|
|
225
|
+
personaId: z.string().uuid(),
|
|
226
|
+
question: z.string().min(1),
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
export const debateRequestSchema = z.object({
|
|
230
|
+
personaIds: z.tuple([z.string().uuid(), z.string().uuid()]),
|
|
231
|
+
topic: z.string().optional(),
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
export const steelmanRequestSchema = z.object({
|
|
235
|
+
askingPersonaId: z.string().uuid(),
|
|
236
|
+
targetPersonaId: z.string().uuid(),
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
// ============================================================================
|
|
240
|
+
// Deliberation Schemas
|
|
241
|
+
// ============================================================================
|
|
242
|
+
|
|
243
|
+
export const ledgerEntryTypeSchema = z.enum([
|
|
244
|
+
'problem_statement',
|
|
245
|
+
'analysis',
|
|
246
|
+
'proposal',
|
|
247
|
+
'response',
|
|
248
|
+
'context_acceptance',
|
|
249
|
+
'context_rejection',
|
|
250
|
+
'manager_question',
|
|
251
|
+
'manager_redirect',
|
|
252
|
+
'round_summary',
|
|
253
|
+
'decision',
|
|
254
|
+
'plan',
|
|
255
|
+
'work_directive',
|
|
256
|
+
'work_output',
|
|
257
|
+
'review',
|
|
258
|
+
'revision_request',
|
|
259
|
+
're_deliberation',
|
|
260
|
+
'cancellation',
|
|
261
|
+
'error',
|
|
262
|
+
'decomposition',
|
|
263
|
+
'module_directive',
|
|
264
|
+
'module_output',
|
|
265
|
+
'code_review',
|
|
266
|
+
'test_result',
|
|
267
|
+
'debug_fix',
|
|
268
|
+
]);
|
|
269
|
+
|
|
270
|
+
export const deliberationPhaseSchema = z.enum([
|
|
271
|
+
'created',
|
|
272
|
+
'problem_framing',
|
|
273
|
+
'round_independent',
|
|
274
|
+
'round_interactive',
|
|
275
|
+
'round_waiting_for_manager',
|
|
276
|
+
'planning',
|
|
277
|
+
'deciding',
|
|
278
|
+
'directing',
|
|
279
|
+
'executing',
|
|
280
|
+
'reviewing',
|
|
281
|
+
'revising',
|
|
282
|
+
'decomposing',
|
|
283
|
+
'implementing',
|
|
284
|
+
'code_reviewing',
|
|
285
|
+
'testing',
|
|
286
|
+
'debugging',
|
|
287
|
+
'paused',
|
|
288
|
+
'completed',
|
|
289
|
+
'cancelled',
|
|
290
|
+
'failed',
|
|
291
|
+
]);
|
|
292
|
+
|
|
293
|
+
export const artifactTypeSchema = z.enum([
|
|
294
|
+
'context',
|
|
295
|
+
'decision',
|
|
296
|
+
'plan',
|
|
297
|
+
'directive',
|
|
298
|
+
'output',
|
|
299
|
+
]);
|
|
300
|
+
|
|
301
|
+
export const summaryModeSchema = z.enum([
|
|
302
|
+
'manager',
|
|
303
|
+
'automatic',
|
|
304
|
+
'hybrid',
|
|
305
|
+
'none',
|
|
306
|
+
]);
|
|
307
|
+
|
|
308
|
+
export const consultantErrorPolicySchema = z.enum(['retry', 'skip', 'fail']);
|
|
309
|
+
|
|
310
|
+
export const artifactRefSchema = z.object({
|
|
311
|
+
artifactType: artifactTypeSchema,
|
|
312
|
+
artifactId: z.string(),
|
|
313
|
+
version: z.number().int().optional(),
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
export const contextArtifactSchema = z.object({
|
|
317
|
+
id: z.string().uuid(),
|
|
318
|
+
councilId: z.string().uuid(),
|
|
319
|
+
version: z.number().int().min(1),
|
|
320
|
+
content: z.string().min(1),
|
|
321
|
+
createdFromVersion: z.number().int().optional(),
|
|
322
|
+
changeSummary: z.string(),
|
|
323
|
+
authorRole: deliberationRoleSchema,
|
|
324
|
+
authorPersonaId: z.string().optional(),
|
|
325
|
+
roundNumber: z.number().int().optional(),
|
|
326
|
+
createdAt: z.string().datetime(),
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
export const decisionArtifactSchema = z.object({
|
|
330
|
+
id: z.string().uuid(),
|
|
331
|
+
councilId: z.string().uuid(),
|
|
332
|
+
content: z.string().min(1),
|
|
333
|
+
contextVersionAtDecision: z.number().int().min(1),
|
|
334
|
+
acceptanceCriteria: z.string().optional(),
|
|
335
|
+
createdAt: z.string().datetime(),
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
export const planArtifactSchema = z.object({
|
|
339
|
+
id: z.string().uuid(),
|
|
340
|
+
councilId: z.string().uuid(),
|
|
341
|
+
content: z.string().min(1),
|
|
342
|
+
decisionId: z.string().uuid(),
|
|
343
|
+
createdAt: z.string().datetime(),
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
export const directiveArtifactSchema = z.object({
|
|
347
|
+
id: z.string().uuid(),
|
|
348
|
+
councilId: z.string().uuid(),
|
|
349
|
+
content: z.string().min(1),
|
|
350
|
+
decisionId: z.string().uuid(),
|
|
351
|
+
planId: z.string().uuid().optional(),
|
|
352
|
+
createdAt: z.string().datetime(),
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
export const outputArtifactSchema = z.object({
|
|
356
|
+
id: z.string().uuid(),
|
|
357
|
+
councilId: z.string().uuid(),
|
|
358
|
+
content: z.string().min(1),
|
|
359
|
+
directiveId: z.string().uuid(),
|
|
360
|
+
version: z.number().int().min(1),
|
|
361
|
+
isRevision: z.boolean(),
|
|
362
|
+
previousOutputId: z.string().uuid().optional(),
|
|
363
|
+
createdAt: z.string().datetime(),
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
export const contextPatchStatusSchema = z.enum(['pending', 'accepted', 'rejected']);
|
|
367
|
+
|
|
368
|
+
export const contextPatchSchema = z.object({
|
|
369
|
+
id: z.string().uuid(),
|
|
370
|
+
councilId: z.string().uuid(),
|
|
371
|
+
targetContextId: z.string().uuid(),
|
|
372
|
+
baseVersion: z.number().int().min(1),
|
|
373
|
+
diff: z.string().min(1),
|
|
374
|
+
rationale: z.string().min(1),
|
|
375
|
+
authorPersonaId: z.string().uuid(),
|
|
376
|
+
roundNumber: z.number().int().min(1),
|
|
377
|
+
status: contextPatchStatusSchema,
|
|
378
|
+
reviewedBy: z.string().uuid().optional(),
|
|
379
|
+
reviewReason: z.string().optional(),
|
|
380
|
+
createdAt: z.string().datetime(),
|
|
381
|
+
reviewedAt: z.string().datetime().optional(),
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
export const reviewOutcomeSchema = z.enum(['accept', 'revise', 're_deliberate']);
|
|
385
|
+
|
|
386
|
+
export const ledgerEntrySchema = z.object({
|
|
387
|
+
id: z.string().uuid(),
|
|
388
|
+
timestamp: z.string().datetime(),
|
|
389
|
+
authorRole: deliberationRoleSchema,
|
|
390
|
+
authorPersonaId: z.string(),
|
|
391
|
+
entryType: ledgerEntryTypeSchema,
|
|
392
|
+
phase: deliberationPhaseSchema,
|
|
393
|
+
roundNumber: z.number().int().optional(),
|
|
394
|
+
content: z.string(),
|
|
395
|
+
structured: z.record(z.string(), z.unknown()).optional(),
|
|
396
|
+
artifactRefs: z.array(artifactRefSchema).optional(),
|
|
397
|
+
referencedEntries: z.array(z.string().uuid()).optional(),
|
|
398
|
+
reviewOutcome: reviewOutcomeSchema.optional(),
|
|
399
|
+
tokensUsed: z.number().int().min(0).optional(),
|
|
400
|
+
latencyMs: z.number().int().min(0).optional(),
|
|
401
|
+
error: z.string().optional(),
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
export const deliberationRoleAssignmentSchema = z.object({
|
|
405
|
+
personaId: z.string().uuid(),
|
|
406
|
+
role: deliberationRoleSchema,
|
|
407
|
+
focusArea: z.string().optional(),
|
|
408
|
+
stance: z.string().optional(),
|
|
409
|
+
suppressPersona: z.boolean().optional(),
|
|
410
|
+
writePermissions: z.boolean().optional(),
|
|
411
|
+
allowedServerIds: z.array(z.string()).optional(),
|
|
412
|
+
toolAccess: z.enum(['full', 'none']).optional(),
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
export const patchDecisionSchema = z.object({
|
|
416
|
+
patchId: z.string().uuid(),
|
|
417
|
+
accepted: z.boolean(),
|
|
418
|
+
reason: z.string(),
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
export const managerEvaluationSchema = z.object({
|
|
422
|
+
action: z.enum(['continue', 'decide', 'redirect']),
|
|
423
|
+
reasoning: z.string(),
|
|
424
|
+
confidence: z.number().min(0).max(1).nullish().transform(v => v ?? undefined),
|
|
425
|
+
missingInformation: z.array(z.string()).nullish().transform(v => v ?? undefined),
|
|
426
|
+
question: z.string().nullish().transform(v => v ?? undefined),
|
|
427
|
+
patchDecisions: z.array(patchDecisionSchema).nullish().transform(v => v ?? undefined),
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
export const managerReviewSchema = z.object({
|
|
431
|
+
verdict: reviewOutcomeSchema,
|
|
432
|
+
reasoning: z.string(),
|
|
433
|
+
feedback: z.string().nullish().transform(v => v ?? undefined),
|
|
434
|
+
newInformation: z.string().nullish().transform(v => v ?? undefined),
|
|
435
|
+
});
|
|
436
|
+
|
|
437
|
+
export const deliberationConfigSchema = z.object({
|
|
438
|
+
enabled: z.boolean(),
|
|
439
|
+
roleAssignments: z.array(deliberationRoleAssignmentSchema),
|
|
440
|
+
minRounds: z.number().int().min(1).default(1),
|
|
441
|
+
maxRounds: z.number().int().min(0).max(10).default(4),
|
|
442
|
+
maxRevisions: z.number().int().min(0).max(10).default(3),
|
|
443
|
+
decisionCriteria: z.array(z.string()).optional(),
|
|
444
|
+
summaryMode: summaryModeSchema.default('manager'),
|
|
445
|
+
summarizeAfterRound: z.number().int().min(1).default(2),
|
|
446
|
+
contextTokenBudget: z.number().int().min(1000).default(80000),
|
|
447
|
+
consultantErrorPolicy: consultantErrorPolicySchema.default('retry'),
|
|
448
|
+
maxRetries: z.number().int().min(0).max(5).default(2),
|
|
449
|
+
requirePlan: z.boolean().default(false),
|
|
450
|
+
consultantExecution: z.enum(['parallel', 'sequential']).default('sequential'),
|
|
451
|
+
workingDirectory: z.string().optional(),
|
|
452
|
+
directoryConstrained: z.boolean().optional(),
|
|
453
|
+
savedProblem: z.string().optional(),
|
|
454
|
+
expectedOutput: z.string().optional(),
|
|
455
|
+
saveDeliberation: z.boolean().optional(),
|
|
456
|
+
saveDeliberationMode: z.enum(['full', 'abbreviated']).optional(),
|
|
457
|
+
maxWordsPerResponse: z.number().optional(),
|
|
458
|
+
stepType: z.enum(['council', 'code_planning', 'analysis', 'agent', 'coding', 'review', 'enrich']).optional(),
|
|
459
|
+
testCommand: z.string().optional(),
|
|
460
|
+
maxDebugCycles: z.number().int().optional(),
|
|
461
|
+
maxReviewCycles: z.number().int().optional(),
|
|
462
|
+
allowedServerIds: z.array(z.string()).optional(),
|
|
463
|
+
bootstrapContext: z.boolean().optional(),
|
|
464
|
+
});
|
|
465
|
+
|
|
466
|
+
export const deliberationStateSchema = z.object({
|
|
467
|
+
currentPhase: deliberationPhaseSchema,
|
|
468
|
+
previousPhase: deliberationPhaseSchema.optional(),
|
|
469
|
+
currentRound: z.number().int().min(0),
|
|
470
|
+
roundRunId: z.string(),
|
|
471
|
+
maxRounds: z.number().int().min(0),
|
|
472
|
+
revisionCount: z.number().int().min(0),
|
|
473
|
+
maxRevisions: z.number().int().min(0),
|
|
474
|
+
roundSubmissions: z.record(z.string(), z.array(z.string())),
|
|
475
|
+
roundSummaries: z.record(z.string(), z.string()),
|
|
476
|
+
activeContextId: z.string(),
|
|
477
|
+
activeContextVersion: z.number().int().min(0),
|
|
478
|
+
pendingPatches: z.array(z.string()),
|
|
479
|
+
managerLastEvaluation: managerEvaluationSchema.nullish().transform(v => v ?? undefined),
|
|
480
|
+
finalDecisionId: z.string().nullish().transform(v => v ?? undefined),
|
|
481
|
+
workDirectiveId: z.string().nullish().transform(v => v ?? undefined),
|
|
482
|
+
currentOutputId: z.string().nullish().transform(v => v ?? undefined),
|
|
483
|
+
reDeliberationCount: z.number().int().min(0).default(0).optional(),
|
|
484
|
+
errorLog: z.array(z.string()),
|
|
485
|
+
completionSummary: z.string().nullish().transform(v => v ?? undefined),
|
|
486
|
+
});
|
|
487
|
+
|
|
488
|
+
export const ledgerIndexSchema = z.object({
|
|
489
|
+
councilId: z.string().uuid(),
|
|
490
|
+
entryCount: z.number().int().min(0),
|
|
491
|
+
chunkCount: z.number().int().min(0),
|
|
492
|
+
chunkBoundaries: z.array(z.number().int()),
|
|
493
|
+
totalTokens: z.number().int().min(0),
|
|
494
|
+
lastUpdated: z.string().datetime(),
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
// Extended council schema with deliberation support
|
|
498
|
+
export const councilWithDeliberationSchema = councilSchema.extend({
|
|
499
|
+
deliberation: deliberationConfigSchema.optional(),
|
|
500
|
+
deliberationState: deliberationStateSchema.optional(),
|
|
501
|
+
});
|
|
502
|
+
|
|
503
|
+
// ============================================================================
|
|
504
|
+
// Type Exports
|
|
505
|
+
// ============================================================================
|
|
506
|
+
|
|
507
|
+
export type PredispositionInput = z.infer<typeof predispositionSchema>;
|
|
508
|
+
export type PersonaInput = z.infer<typeof personaSchema>;
|
|
509
|
+
export type CouncilInput = z.infer<typeof councilSchema>;
|
|
510
|
+
export type OrchestrationConfigInput = z.infer<typeof orchestrationConfigSchema>;
|
|
511
|
+
export type SharedContextInput = z.infer<typeof sharedContextSchema>;
|
|
512
|
+
export type CouncilMessageInput = z.infer<typeof councilMessageSchema>;
|
|
513
|
+
export type ResolutionInput = z.infer<typeof resolutionSchema>;
|
|
514
|
+
|
|
515
|
+
// Deliberation type exports
|
|
516
|
+
export type DeliberationRoleInput = z.infer<typeof deliberationRoleSchema>;
|
|
517
|
+
export type LedgerEntryTypeInput = z.infer<typeof ledgerEntryTypeSchema>;
|
|
518
|
+
export type DeliberationPhaseInput = z.infer<typeof deliberationPhaseSchema>;
|
|
519
|
+
export type ArtifactTypeInput = z.infer<typeof artifactTypeSchema>;
|
|
520
|
+
export type SummaryModeInput = z.infer<typeof summaryModeSchema>;
|
|
521
|
+
export type ContextArtifactInput = z.infer<typeof contextArtifactSchema>;
|
|
522
|
+
export type DecisionArtifactInput = z.infer<typeof decisionArtifactSchema>;
|
|
523
|
+
export type PlanArtifactInput = z.infer<typeof planArtifactSchema>;
|
|
524
|
+
export type DirectiveArtifactInput = z.infer<typeof directiveArtifactSchema>;
|
|
525
|
+
export type OutputArtifactInput = z.infer<typeof outputArtifactSchema>;
|
|
526
|
+
export type ContextPatchInput = z.infer<typeof contextPatchSchema>;
|
|
527
|
+
export type LedgerEntryInput = z.infer<typeof ledgerEntrySchema>;
|
|
528
|
+
export type DeliberationRoleAssignmentInput = z.infer<typeof deliberationRoleAssignmentSchema>;
|
|
529
|
+
export type ManagerEvaluationInput = z.infer<typeof managerEvaluationSchema>;
|
|
530
|
+
export type ManagerReviewInput = z.infer<typeof managerReviewSchema>;
|
|
531
|
+
export type DeliberationConfigInput = z.infer<typeof deliberationConfigSchema>;
|
|
532
|
+
export type DeliberationStateInput = z.infer<typeof deliberationStateSchema>;
|
|
533
|
+
export type LedgerIndexInput = z.infer<typeof ledgerIndexSchema>;
|
|
534
|
+
|
|
535
|
+
// ============================================================================
|
|
536
|
+
// Validation Helpers
|
|
537
|
+
// ============================================================================
|
|
538
|
+
|
|
539
|
+
export function validateCouncil(data: unknown) {
|
|
540
|
+
return councilSchema.safeParse(data);
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
export function validatePersona(data: unknown) {
|
|
544
|
+
return personaSchema.safeParse(data);
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
export function validateCreateCouncilRequest(data: unknown) {
|
|
548
|
+
return createCouncilRequestSchema.safeParse(data);
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
export function validateAddPersonaRequest(data: unknown) {
|
|
552
|
+
return addPersonaRequestSchema.safeParse(data);
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
/**
|
|
556
|
+
* Validate and provide helpful error messages
|
|
557
|
+
*/
|
|
558
|
+
export function validateWithErrors<T>(
|
|
559
|
+
schema: z.ZodSchema<T>,
|
|
560
|
+
data: unknown
|
|
561
|
+
): { success: true; data: T } | { success: false; errors: string[] } {
|
|
562
|
+
const result = schema.safeParse(data);
|
|
563
|
+
if (result.success) {
|
|
564
|
+
return { success: true, data: result.data };
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
const errors = result.error.issues.map((issue) => {
|
|
568
|
+
const path = issue.path.join('.');
|
|
569
|
+
return path ? `${path}: ${issue.message}` : issue.message;
|
|
570
|
+
});
|
|
571
|
+
|
|
572
|
+
return { success: false, errors };
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
// ============================================================================
|
|
576
|
+
// Deliberation Validation Helpers
|
|
577
|
+
// ============================================================================
|
|
578
|
+
|
|
579
|
+
export function validateDeliberationConfig(data: unknown) {
|
|
580
|
+
return deliberationConfigSchema.safeParse(data);
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
export function validateDeliberationState(data: unknown) {
|
|
584
|
+
return deliberationStateSchema.safeParse(data);
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
export function validateLedgerEntry(data: unknown) {
|
|
588
|
+
return ledgerEntrySchema.safeParse(data);
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
export function validateContextArtifact(data: unknown) {
|
|
592
|
+
return contextArtifactSchema.safeParse(data);
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
export function validateContextPatch(data: unknown) {
|
|
596
|
+
return contextPatchSchema.safeParse(data);
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
export function validateManagerEvaluation(data: unknown) {
|
|
600
|
+
return managerEvaluationSchema.safeParse(data);
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
export function validateManagerReview(data: unknown) {
|
|
604
|
+
return managerReviewSchema.safeParse(data);
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
export function validateDeliberationRoleAssignment(data: unknown) {
|
|
608
|
+
return deliberationRoleAssignmentSchema.safeParse(data);
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
export function validateCouncilWithDeliberation(data: unknown) {
|
|
612
|
+
return councilWithDeliberationSchema.safeParse(data);
|
|
613
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build Command Auto-Detection
|
|
3
|
+
* Scans project files to determine the appropriate build/compile command.
|
|
4
|
+
* Reuses ReadFileFn type from test-detect.ts.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { ReadFileFn } from './test-detect';
|
|
8
|
+
|
|
9
|
+
export interface DetectedBuild {
|
|
10
|
+
command: string;
|
|
11
|
+
framework: string;
|
|
12
|
+
confidence: 'high' | 'medium' | 'low';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Detect the appropriate build command for a project directory.
|
|
17
|
+
* Checks common project files in priority order.
|
|
18
|
+
*
|
|
19
|
+
* @param workingDir Absolute path to the project root
|
|
20
|
+
* @param readFile Optional callback that reads a file and returns its content
|
|
21
|
+
* (or null if not found). When omitted, detection is skipped.
|
|
22
|
+
*/
|
|
23
|
+
export async function detectBuildCommand(
|
|
24
|
+
workingDir: string,
|
|
25
|
+
readFile?: ReadFileFn,
|
|
26
|
+
): Promise<DetectedBuild | null> {
|
|
27
|
+
if (!readFile) return null;
|
|
28
|
+
|
|
29
|
+
const fileExists = async (path: string): Promise<string | null> => {
|
|
30
|
+
try {
|
|
31
|
+
return await readFile(path);
|
|
32
|
+
} catch {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// 1. package.json — Node.js projects
|
|
38
|
+
const packageJson = await fileExists(`${workingDir}/package.json`);
|
|
39
|
+
if (packageJson) {
|
|
40
|
+
try {
|
|
41
|
+
const pkg = JSON.parse(packageJson);
|
|
42
|
+
if (pkg.scripts?.build) {
|
|
43
|
+
return { command: 'npm run build', framework: 'npm', confidence: 'high' };
|
|
44
|
+
}
|
|
45
|
+
} catch { /* invalid JSON, skip */ }
|
|
46
|
+
|
|
47
|
+
// No build script — check for tsconfig.json → tsc --noEmit
|
|
48
|
+
const tsconfig = await fileExists(`${workingDir}/tsconfig.json`);
|
|
49
|
+
if (tsconfig) {
|
|
50
|
+
return { command: 'npx tsc --noEmit', framework: 'tsc', confidence: 'medium' };
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// 2. Cargo.toml — Rust projects
|
|
55
|
+
const cargoToml = await fileExists(`${workingDir}/Cargo.toml`);
|
|
56
|
+
if (cargoToml) {
|
|
57
|
+
return { command: 'cargo build', framework: 'cargo', confidence: 'high' };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// 3. go.mod — Go projects
|
|
61
|
+
const goMod = await fileExists(`${workingDir}/go.mod`);
|
|
62
|
+
if (goMod) {
|
|
63
|
+
return { command: 'go build ./...', framework: 'go', confidence: 'high' };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// 4. Makefile with build target
|
|
67
|
+
const makefile = await fileExists(`${workingDir}/Makefile`);
|
|
68
|
+
if (makefile && /^build\s*:/m.test(makefile)) {
|
|
69
|
+
return { command: 'make build', framework: 'make', confidence: 'medium' };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return null;
|
|
73
|
+
}
|