File size: 2,303 Bytes
a8f4b72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { randomUUID } from 'node:crypto';
import { getCouncilTemplate } from '../../council-engine/src/index.mjs';
import { evaluateExecutionGate } from '../../governance-fabric/src/index.mjs';

const intentRules = [
  ['governance', /policy|permission|trust|privacy|risk|approval|audit/],
  ['infrastructure', /deploy|database|docker|runtime|infrastructure|install|server/],
  ['architecture', /design|architecture|system|structure|interface|boundary/],
  ['implementation', /build|implement|code|create|app|feature|fix|change/],
  ['evolution', /improv|evol|compare|roadmap|gap|frontier|obsolete/]
];

export function classifyIntent(question) {
  const normalized = String(question ?? '').trim().toLowerCase();
  for (const [intent, expression] of intentRules) {
    if (expression.test(normalized)) return intent;
  }
  return 'research';
}

export function createPlanDraft({ question, project = '', integrations = {} }) {
  const cleanQuestion = String(question ?? '').trim();
  if (!cleanQuestion) throw new TypeError('A question is required to create a plan.');
  if (cleanQuestion.length > 700) throw new RangeError('Questions must be 700 characters or fewer.');

  const intent = classifyIntent(cleanQuestion);
  const council = getCouncilTemplate(intent);
  const gate = evaluateExecutionGate({ integrations, hasApproval: false });
  const projectName = String(project ?? '').trim() || 'Workspace level';
  return {
    id: randomUUID(),
    question: cleanQuestion,
    project: projectName,
    intent,
    council: council.name,
    agents: council.agents,
    model: 'Not configured',
    datasets: String(project ?? '').trim() ? `${projectName} project context (local prototype)` : 'No dataset connected',
    tools: 'No tool adapters configured',
    logic: 'Draft created; feasibility has not been verified against a runtime.',
    governance: `${gate.status}: ${gate.reason}`,
    governanceGate: gate,
    status: 'Draft',
    executionReady: gate.allowed,
    created: new Date().toISOString()
  };
}

export class OperationsAgent {
  createCouncil(task) {
    const plan = createPlanDraft({ question: task });
    console.log(`Creating ${plan.council} for ${task}`);
    return plan.agents;
  }

  plan(task, project) {
    return createPlanDraft({ question: task, project });
  }
}