@soleri/core 2.0.2 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/brain/brain.d.ts +14 -50
- package/dist/brain/brain.d.ts.map +1 -1
- package/dist/brain/brain.js +207 -16
- package/dist/brain/brain.js.map +1 -1
- package/dist/brain/intelligence.d.ts +86 -0
- package/dist/brain/intelligence.d.ts.map +1 -0
- package/dist/brain/intelligence.js +771 -0
- package/dist/brain/intelligence.js.map +1 -0
- package/dist/brain/types.d.ts +197 -0
- package/dist/brain/types.d.ts.map +1 -0
- package/dist/brain/types.js +2 -0
- package/dist/brain/types.js.map +1 -0
- package/dist/cognee/client.d.ts +35 -0
- package/dist/cognee/client.d.ts.map +1 -0
- package/dist/cognee/client.js +291 -0
- package/dist/cognee/client.js.map +1 -0
- package/dist/cognee/types.d.ts +46 -0
- package/dist/cognee/types.d.ts.map +1 -0
- package/dist/cognee/types.js +3 -0
- package/dist/cognee/types.js.map +1 -0
- package/dist/control/identity-manager.d.ts +22 -0
- package/dist/control/identity-manager.d.ts.map +1 -0
- package/dist/control/identity-manager.js +233 -0
- package/dist/control/identity-manager.js.map +1 -0
- package/dist/control/intent-router.d.ts +32 -0
- package/dist/control/intent-router.d.ts.map +1 -0
- package/dist/control/intent-router.js +242 -0
- package/dist/control/intent-router.js.map +1 -0
- package/dist/control/types.d.ts +68 -0
- package/dist/control/types.d.ts.map +1 -0
- package/dist/control/types.js +9 -0
- package/dist/control/types.js.map +1 -0
- package/dist/curator/curator.d.ts +29 -0
- package/dist/curator/curator.d.ts.map +1 -1
- package/dist/curator/curator.js +142 -5
- package/dist/curator/curator.js.map +1 -1
- package/dist/facades/types.d.ts +1 -1
- package/dist/governance/governance.d.ts +42 -0
- package/dist/governance/governance.d.ts.map +1 -0
- package/dist/governance/governance.js +488 -0
- package/dist/governance/governance.js.map +1 -0
- package/dist/governance/index.d.ts +3 -0
- package/dist/governance/index.d.ts.map +1 -0
- package/dist/governance/index.js +2 -0
- package/dist/governance/index.js.map +1 -0
- package/dist/governance/types.d.ts +102 -0
- package/dist/governance/types.d.ts.map +1 -0
- package/dist/governance/types.js +3 -0
- package/dist/governance/types.js.map +1 -0
- package/dist/index.d.ts +35 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +32 -1
- package/dist/index.js.map +1 -1
- package/dist/llm/llm-client.d.ts.map +1 -1
- package/dist/llm/llm-client.js +9 -2
- package/dist/llm/llm-client.js.map +1 -1
- package/dist/logging/logger.d.ts +37 -0
- package/dist/logging/logger.d.ts.map +1 -0
- package/dist/logging/logger.js +145 -0
- package/dist/logging/logger.js.map +1 -0
- package/dist/logging/types.d.ts +19 -0
- package/dist/logging/types.d.ts.map +1 -0
- package/dist/logging/types.js +2 -0
- package/dist/logging/types.js.map +1 -0
- package/dist/loop/loop-manager.d.ts +49 -0
- package/dist/loop/loop-manager.d.ts.map +1 -0
- package/dist/loop/loop-manager.js +105 -0
- package/dist/loop/loop-manager.js.map +1 -0
- package/dist/loop/types.d.ts +35 -0
- package/dist/loop/types.d.ts.map +1 -0
- package/dist/loop/types.js +8 -0
- package/dist/loop/types.js.map +1 -0
- package/dist/planning/gap-analysis.d.ts +29 -0
- package/dist/planning/gap-analysis.d.ts.map +1 -0
- package/dist/planning/gap-analysis.js +265 -0
- package/dist/planning/gap-analysis.js.map +1 -0
- package/dist/planning/gap-types.d.ts +29 -0
- package/dist/planning/gap-types.d.ts.map +1 -0
- package/dist/planning/gap-types.js +28 -0
- package/dist/planning/gap-types.js.map +1 -0
- package/dist/planning/planner.d.ts +150 -1
- package/dist/planning/planner.d.ts.map +1 -1
- package/dist/planning/planner.js +365 -2
- package/dist/planning/planner.js.map +1 -1
- package/dist/project/project-registry.d.ts +79 -0
- package/dist/project/project-registry.d.ts.map +1 -0
- package/dist/project/project-registry.js +276 -0
- package/dist/project/project-registry.js.map +1 -0
- package/dist/project/types.d.ts +28 -0
- package/dist/project/types.d.ts.map +1 -0
- package/dist/project/types.js +5 -0
- package/dist/project/types.js.map +1 -0
- package/dist/runtime/admin-extra-ops.d.ts +13 -0
- package/dist/runtime/admin-extra-ops.d.ts.map +1 -0
- package/dist/runtime/admin-extra-ops.js +284 -0
- package/dist/runtime/admin-extra-ops.js.map +1 -0
- package/dist/runtime/admin-ops.d.ts +15 -0
- package/dist/runtime/admin-ops.d.ts.map +1 -0
- package/dist/runtime/admin-ops.js +322 -0
- package/dist/runtime/admin-ops.js.map +1 -0
- package/dist/runtime/capture-ops.d.ts +15 -0
- package/dist/runtime/capture-ops.d.ts.map +1 -0
- package/dist/runtime/capture-ops.js +345 -0
- package/dist/runtime/capture-ops.js.map +1 -0
- package/dist/runtime/core-ops.d.ts +7 -3
- package/dist/runtime/core-ops.d.ts.map +1 -1
- package/dist/runtime/core-ops.js +646 -15
- package/dist/runtime/core-ops.js.map +1 -1
- package/dist/runtime/curator-extra-ops.d.ts +9 -0
- package/dist/runtime/curator-extra-ops.d.ts.map +1 -0
- package/dist/runtime/curator-extra-ops.js +59 -0
- package/dist/runtime/curator-extra-ops.js.map +1 -0
- package/dist/runtime/domain-ops.d.ts.map +1 -1
- package/dist/runtime/domain-ops.js +59 -13
- package/dist/runtime/domain-ops.js.map +1 -1
- package/dist/runtime/grading-ops.d.ts +14 -0
- package/dist/runtime/grading-ops.d.ts.map +1 -0
- package/dist/runtime/grading-ops.js +105 -0
- package/dist/runtime/grading-ops.js.map +1 -0
- package/dist/runtime/loop-ops.d.ts +13 -0
- package/dist/runtime/loop-ops.d.ts.map +1 -0
- package/dist/runtime/loop-ops.js +179 -0
- package/dist/runtime/loop-ops.js.map +1 -0
- package/dist/runtime/memory-cross-project-ops.d.ts +12 -0
- package/dist/runtime/memory-cross-project-ops.d.ts.map +1 -0
- package/dist/runtime/memory-cross-project-ops.js +165 -0
- package/dist/runtime/memory-cross-project-ops.js.map +1 -0
- package/dist/runtime/memory-extra-ops.d.ts +13 -0
- package/dist/runtime/memory-extra-ops.d.ts.map +1 -0
- package/dist/runtime/memory-extra-ops.js +173 -0
- package/dist/runtime/memory-extra-ops.js.map +1 -0
- package/dist/runtime/orchestrate-ops.d.ts +17 -0
- package/dist/runtime/orchestrate-ops.d.ts.map +1 -0
- package/dist/runtime/orchestrate-ops.js +240 -0
- package/dist/runtime/orchestrate-ops.js.map +1 -0
- package/dist/runtime/planning-extra-ops.d.ts +17 -0
- package/dist/runtime/planning-extra-ops.d.ts.map +1 -0
- package/dist/runtime/planning-extra-ops.js +300 -0
- package/dist/runtime/planning-extra-ops.js.map +1 -0
- package/dist/runtime/project-ops.d.ts +15 -0
- package/dist/runtime/project-ops.d.ts.map +1 -0
- package/dist/runtime/project-ops.js +181 -0
- package/dist/runtime/project-ops.js.map +1 -0
- package/dist/runtime/runtime.d.ts.map +1 -1
- package/dist/runtime/runtime.js +48 -1
- package/dist/runtime/runtime.js.map +1 -1
- package/dist/runtime/types.d.ts +23 -0
- package/dist/runtime/types.d.ts.map +1 -1
- package/dist/runtime/vault-extra-ops.d.ts +9 -0
- package/dist/runtime/vault-extra-ops.d.ts.map +1 -0
- package/dist/runtime/vault-extra-ops.js +195 -0
- package/dist/runtime/vault-extra-ops.js.map +1 -0
- package/dist/telemetry/telemetry.d.ts +48 -0
- package/dist/telemetry/telemetry.d.ts.map +1 -0
- package/dist/telemetry/telemetry.js +87 -0
- package/dist/telemetry/telemetry.js.map +1 -0
- package/dist/vault/vault.d.ts +94 -0
- package/dist/vault/vault.d.ts.map +1 -1
- package/dist/vault/vault.js +340 -1
- package/dist/vault/vault.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/admin-extra-ops.test.ts +420 -0
- package/src/__tests__/admin-ops.test.ts +271 -0
- package/src/__tests__/brain-intelligence.test.ts +828 -0
- package/src/__tests__/brain.test.ts +396 -27
- package/src/__tests__/capture-ops.test.ts +509 -0
- package/src/__tests__/cognee-client.test.ts +524 -0
- package/src/__tests__/core-ops.test.ts +341 -49
- package/src/__tests__/curator-extra-ops.test.ts +359 -0
- package/src/__tests__/curator.test.ts +126 -31
- package/src/__tests__/domain-ops.test.ts +111 -9
- package/src/__tests__/governance.test.ts +522 -0
- package/src/__tests__/grading-ops.test.ts +340 -0
- package/src/__tests__/identity-manager.test.ts +243 -0
- package/src/__tests__/intent-router.test.ts +222 -0
- package/src/__tests__/logger.test.ts +200 -0
- package/src/__tests__/loop-ops.test.ts +398 -0
- package/src/__tests__/memory-cross-project-ops.test.ts +246 -0
- package/src/__tests__/memory-extra-ops.test.ts +352 -0
- package/src/__tests__/orchestrate-ops.test.ts +284 -0
- package/src/__tests__/planner.test.ts +331 -0
- package/src/__tests__/planning-extra-ops.test.ts +548 -0
- package/src/__tests__/project-ops.test.ts +367 -0
- package/src/__tests__/runtime.test.ts +13 -11
- package/src/__tests__/vault-extra-ops.test.ts +407 -0
- package/src/brain/brain.ts +308 -72
- package/src/brain/intelligence.ts +1230 -0
- package/src/brain/types.ts +214 -0
- package/src/cognee/client.ts +352 -0
- package/src/cognee/types.ts +62 -0
- package/src/control/identity-manager.ts +354 -0
- package/src/control/intent-router.ts +326 -0
- package/src/control/types.ts +102 -0
- package/src/curator/curator.ts +265 -15
- package/src/governance/governance.ts +698 -0
- package/src/governance/index.ts +18 -0
- package/src/governance/types.ts +111 -0
- package/src/index.ts +128 -3
- package/src/llm/llm-client.ts +18 -24
- package/src/logging/logger.ts +154 -0
- package/src/logging/types.ts +21 -0
- package/src/loop/loop-manager.ts +130 -0
- package/src/loop/types.ts +44 -0
- package/src/planning/gap-analysis.ts +506 -0
- package/src/planning/gap-types.ts +58 -0
- package/src/planning/planner.ts +478 -2
- package/src/project/project-registry.ts +358 -0
- package/src/project/types.ts +31 -0
- package/src/runtime/admin-extra-ops.ts +307 -0
- package/src/runtime/admin-ops.ts +329 -0
- package/src/runtime/capture-ops.ts +385 -0
- package/src/runtime/core-ops.ts +747 -26
- package/src/runtime/curator-extra-ops.ts +71 -0
- package/src/runtime/domain-ops.ts +65 -13
- package/src/runtime/grading-ops.ts +121 -0
- package/src/runtime/loop-ops.ts +194 -0
- package/src/runtime/memory-cross-project-ops.ts +192 -0
- package/src/runtime/memory-extra-ops.ts +186 -0
- package/src/runtime/orchestrate-ops.ts +272 -0
- package/src/runtime/planning-extra-ops.ts +327 -0
- package/src/runtime/project-ops.ts +196 -0
- package/src/runtime/runtime.ts +54 -1
- package/src/runtime/types.ts +23 -0
- package/src/runtime/vault-extra-ops.ts +225 -0
- package/src/telemetry/telemetry.ts +118 -0
- package/src/vault/vault.ts +412 -1
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Loop system types — iterative validation loop state tracking.
|
|
3
|
+
*
|
|
4
|
+
* Loops let agents run validate-fix-validate cycles (e.g. token migration,
|
|
5
|
+
* contrast fixes, component builds). In-memory only — session-scoped.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/** Supported loop modes — each maps to a different validation strategy. */
|
|
9
|
+
export type LoopMode =
|
|
10
|
+
| 'token-migration'
|
|
11
|
+
| 'contrast-fix'
|
|
12
|
+
| 'component-build'
|
|
13
|
+
| 'plan-iteration'
|
|
14
|
+
| 'custom';
|
|
15
|
+
|
|
16
|
+
/** Configuration for starting a new loop. */
|
|
17
|
+
export interface LoopConfig {
|
|
18
|
+
mode: LoopMode;
|
|
19
|
+
prompt: string;
|
|
20
|
+
maxIterations: number;
|
|
21
|
+
targetScore?: number;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** A single iteration result within a loop. */
|
|
25
|
+
export interface LoopIteration {
|
|
26
|
+
iteration: number;
|
|
27
|
+
timestamp: string;
|
|
28
|
+
validationScore?: number;
|
|
29
|
+
validationResult?: string;
|
|
30
|
+
passed: boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Loop lifecycle status. */
|
|
34
|
+
export type LoopStatus = 'active' | 'completed' | 'cancelled' | 'max-iterations';
|
|
35
|
+
|
|
36
|
+
/** Full state of a loop (active or historical). */
|
|
37
|
+
export interface LoopState {
|
|
38
|
+
id: string;
|
|
39
|
+
config: LoopConfig;
|
|
40
|
+
iterations: LoopIteration[];
|
|
41
|
+
status: LoopStatus;
|
|
42
|
+
startedAt: string;
|
|
43
|
+
completedAt?: string;
|
|
44
|
+
}
|
|
@@ -0,0 +1,506 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 6-pass gap analysis engine for plan grading.
|
|
3
|
+
* Ported from Salvador MCP's plan-gap-content.ts / plan-gap-technical.ts.
|
|
4
|
+
*
|
|
5
|
+
* Passes:
|
|
6
|
+
* 1. Structure — required fields present and sufficiently long
|
|
7
|
+
* 2. Completeness — measurable objectives, decision rationale, scope exclusions
|
|
8
|
+
* 3. Feasibility — overly broad scope, missing dependency awareness
|
|
9
|
+
* 4. Risk — breaking changes without mitigation, missing verification
|
|
10
|
+
* 5. Clarity — ambiguous language, vague criteria
|
|
11
|
+
* 6. Semantic Quality — generic objectives, shallow rationale, non-concrete approach
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import type { Plan } from './planner.js';
|
|
15
|
+
import type { PlanGap, GapSeverity, GapCategory } from './gap-types.js';
|
|
16
|
+
import {
|
|
17
|
+
generateGapId,
|
|
18
|
+
MIN_OBJECTIVE_LENGTH,
|
|
19
|
+
MIN_SCOPE_LENGTH,
|
|
20
|
+
MIN_DECISION_LENGTH,
|
|
21
|
+
} from './gap-types.js';
|
|
22
|
+
|
|
23
|
+
// ─── Helpers ─────────────────────────────────────────────────────
|
|
24
|
+
|
|
25
|
+
function gap(
|
|
26
|
+
severity: GapSeverity,
|
|
27
|
+
category: GapCategory,
|
|
28
|
+
description: string,
|
|
29
|
+
recommendation: string,
|
|
30
|
+
location?: string,
|
|
31
|
+
trigger?: string,
|
|
32
|
+
): PlanGap {
|
|
33
|
+
return {
|
|
34
|
+
id: generateGapId(),
|
|
35
|
+
severity,
|
|
36
|
+
category,
|
|
37
|
+
description,
|
|
38
|
+
recommendation,
|
|
39
|
+
...(location ? { location } : {}),
|
|
40
|
+
...(trigger ? { _trigger: trigger } : {}),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Combine all task descriptions + titles into a single text blob for analysis. */
|
|
45
|
+
function taskText(plan: Plan): string {
|
|
46
|
+
return plan.tasks.map((t) => `${t.title} ${t.description}`).join(' ');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Check if text contains any of the given patterns (case-insensitive). */
|
|
50
|
+
function containsAny(text: string, patterns: string[]): boolean {
|
|
51
|
+
const lower = text.toLowerCase();
|
|
52
|
+
return patterns.some((p) => lower.includes(p.toLowerCase()));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// ─── Pass 1: Structure ───────────────────────────────────────────
|
|
56
|
+
|
|
57
|
+
function analyzeStructure(plan: Plan): PlanGap[] {
|
|
58
|
+
const gaps: PlanGap[] = [];
|
|
59
|
+
|
|
60
|
+
if (!plan.objective || plan.objective.trim().length < MIN_OBJECTIVE_LENGTH) {
|
|
61
|
+
gaps.push(
|
|
62
|
+
gap(
|
|
63
|
+
'critical',
|
|
64
|
+
'structure',
|
|
65
|
+
plan.objective
|
|
66
|
+
? `Objective too short (${plan.objective.trim().length} chars, need ${MIN_OBJECTIVE_LENGTH}+).`
|
|
67
|
+
: 'Plan has no objective.',
|
|
68
|
+
'Add a clear objective describing what this plan achieves.',
|
|
69
|
+
'objective',
|
|
70
|
+
'missing_or_short_objective',
|
|
71
|
+
),
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (!plan.scope || plan.scope.trim().length < MIN_SCOPE_LENGTH) {
|
|
76
|
+
gaps.push(
|
|
77
|
+
gap(
|
|
78
|
+
'critical',
|
|
79
|
+
'structure',
|
|
80
|
+
plan.scope
|
|
81
|
+
? `Scope too short (${plan.scope.trim().length} chars, need ${MIN_SCOPE_LENGTH}+).`
|
|
82
|
+
: 'Plan has no scope defined.',
|
|
83
|
+
'Define the scope — what is included and excluded.',
|
|
84
|
+
'scope',
|
|
85
|
+
'missing_or_short_scope',
|
|
86
|
+
),
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (plan.tasks.length === 0) {
|
|
91
|
+
gaps.push(
|
|
92
|
+
gap(
|
|
93
|
+
'critical',
|
|
94
|
+
'structure',
|
|
95
|
+
'Plan has no tasks.',
|
|
96
|
+
'Add at least one task to make the plan actionable.',
|
|
97
|
+
'tasks',
|
|
98
|
+
'no_tasks',
|
|
99
|
+
),
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return gaps;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// ─── Pass 2: Completeness ────────────────────────────────────────
|
|
107
|
+
|
|
108
|
+
const METRIC_PATTERNS = [
|
|
109
|
+
/\d+/,
|
|
110
|
+
/percent/i,
|
|
111
|
+
/reduce/i,
|
|
112
|
+
/increase/i,
|
|
113
|
+
/measure/i,
|
|
114
|
+
/target/i,
|
|
115
|
+
/goal/i,
|
|
116
|
+
/kpi/i,
|
|
117
|
+
/metric/i,
|
|
118
|
+
/benchmark/i,
|
|
119
|
+
];
|
|
120
|
+
|
|
121
|
+
const EXCLUSION_KEYWORDS = ['not', 'exclude', 'outside', 'beyond', 'limit', 'except', 'won\'t', 'will not'];
|
|
122
|
+
|
|
123
|
+
function analyzeCompleteness(plan: Plan): PlanGap[] {
|
|
124
|
+
const gaps: PlanGap[] = [];
|
|
125
|
+
|
|
126
|
+
// Objective lacks measurable indicators
|
|
127
|
+
if (plan.objective && !METRIC_PATTERNS.some((p) => p.test(plan.objective))) {
|
|
128
|
+
gaps.push(
|
|
129
|
+
gap(
|
|
130
|
+
'minor',
|
|
131
|
+
'completeness',
|
|
132
|
+
'Objective has no measurable targets or metrics.',
|
|
133
|
+
'Include quantifiable success criteria (numbers, percentages, concrete outcomes).',
|
|
134
|
+
'objective',
|
|
135
|
+
'no_metrics_in_objective',
|
|
136
|
+
),
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Decisions without rationale-like content
|
|
141
|
+
if (plan.decisions.length > 0) {
|
|
142
|
+
for (let i = 0; i < plan.decisions.length; i++) {
|
|
143
|
+
const d = plan.decisions[i];
|
|
144
|
+
if (d.trim().length < MIN_DECISION_LENGTH) {
|
|
145
|
+
gaps.push(
|
|
146
|
+
gap(
|
|
147
|
+
'major',
|
|
148
|
+
'completeness',
|
|
149
|
+
`Decision ${i + 1} is too short (${d.trim().length} chars) — lacks rationale.`,
|
|
150
|
+
'Expand each decision to include the reasoning (why this choice over alternatives).',
|
|
151
|
+
`decisions[${i}]`,
|
|
152
|
+
'short_decision',
|
|
153
|
+
),
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Scope missing exclusions
|
|
160
|
+
if (plan.scope && !containsAny(plan.scope, EXCLUSION_KEYWORDS)) {
|
|
161
|
+
gaps.push(
|
|
162
|
+
gap(
|
|
163
|
+
'minor',
|
|
164
|
+
'completeness',
|
|
165
|
+
'Scope does not mention what is excluded.',
|
|
166
|
+
'Add explicit exclusions to prevent scope creep (e.g., "does NOT include…").',
|
|
167
|
+
'scope',
|
|
168
|
+
'no_exclusions_in_scope',
|
|
169
|
+
),
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return gaps;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// ─── Pass 3: Feasibility ─────────────────────────────────────────
|
|
177
|
+
|
|
178
|
+
const OVERLY_BROAD_PATTERNS = [
|
|
179
|
+
'everything',
|
|
180
|
+
'all systems',
|
|
181
|
+
'entire codebase',
|
|
182
|
+
'complete rewrite',
|
|
183
|
+
'from scratch',
|
|
184
|
+
'total overhaul',
|
|
185
|
+
'rewrite everything',
|
|
186
|
+
];
|
|
187
|
+
|
|
188
|
+
const DEPENDENCY_KEYWORDS = ['depends', 'dependency', 'prerequisite', 'requires', 'blocked', 'before'];
|
|
189
|
+
|
|
190
|
+
function analyzeFeasibility(plan: Plan): PlanGap[] {
|
|
191
|
+
const gaps: PlanGap[] = [];
|
|
192
|
+
const scopeAndTasks = `${plan.scope} ${taskText(plan)}`;
|
|
193
|
+
|
|
194
|
+
// Overly broad scope
|
|
195
|
+
if (containsAny(scopeAndTasks, OVERLY_BROAD_PATTERNS)) {
|
|
196
|
+
gaps.push(
|
|
197
|
+
gap(
|
|
198
|
+
'major',
|
|
199
|
+
'feasibility',
|
|
200
|
+
'Scope contains overly broad indicators — risk of unrealistic delivery.',
|
|
201
|
+
'Narrow the scope to a well-defined subset. Prefer incremental delivery over big-bang rewrites.',
|
|
202
|
+
'scope',
|
|
203
|
+
'overly_broad_scope',
|
|
204
|
+
),
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// No dependency awareness in tasks
|
|
209
|
+
if (plan.tasks.length > 3 && !containsAny(scopeAndTasks, DEPENDENCY_KEYWORDS)) {
|
|
210
|
+
const hasDeps = plan.tasks.some((t) => t.dependsOn && t.dependsOn.length > 0);
|
|
211
|
+
if (!hasDeps) {
|
|
212
|
+
gaps.push(
|
|
213
|
+
gap(
|
|
214
|
+
'minor',
|
|
215
|
+
'feasibility',
|
|
216
|
+
`${plan.tasks.length} tasks with no dependency mentions — execution order unclear.`,
|
|
217
|
+
'Identify dependencies between tasks or add explicit ordering notes.',
|
|
218
|
+
'tasks',
|
|
219
|
+
'no_dependency_awareness',
|
|
220
|
+
),
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
return gaps;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// ─── Pass 4: Risk ────────────────────────────────────────────────
|
|
229
|
+
|
|
230
|
+
const BREAKING_CHANGE_KEYWORDS = [
|
|
231
|
+
'breaking change',
|
|
232
|
+
'breaking',
|
|
233
|
+
'migration',
|
|
234
|
+
'deprecate',
|
|
235
|
+
'remove api',
|
|
236
|
+
'remove endpoint',
|
|
237
|
+
'schema change',
|
|
238
|
+
'database migration',
|
|
239
|
+
];
|
|
240
|
+
|
|
241
|
+
const MITIGATION_KEYWORDS = [
|
|
242
|
+
'rollback',
|
|
243
|
+
'backward compatible',
|
|
244
|
+
'backwards compatible',
|
|
245
|
+
'feature flag',
|
|
246
|
+
'gradual',
|
|
247
|
+
'phased',
|
|
248
|
+
'fallback',
|
|
249
|
+
'backup',
|
|
250
|
+
'canary',
|
|
251
|
+
'blue-green',
|
|
252
|
+
];
|
|
253
|
+
|
|
254
|
+
const VERIFICATION_KEYWORDS = ['test', 'verify', 'validate', 'check', 'assert', 'confirm', 'spec', 'coverage'];
|
|
255
|
+
|
|
256
|
+
function analyzeRisk(plan: Plan): PlanGap[] {
|
|
257
|
+
const gaps: PlanGap[] = [];
|
|
258
|
+
const allText = `${plan.objective} ${plan.scope} ${taskText(plan)} ${plan.decisions.join(' ')}`;
|
|
259
|
+
|
|
260
|
+
// Breaking changes without mitigation
|
|
261
|
+
if (containsAny(allText, BREAKING_CHANGE_KEYWORDS) && !containsAny(allText, MITIGATION_KEYWORDS)) {
|
|
262
|
+
gaps.push(
|
|
263
|
+
gap(
|
|
264
|
+
'major',
|
|
265
|
+
'risk',
|
|
266
|
+
'Plan involves breaking changes but mentions no mitigation strategy.',
|
|
267
|
+
'Add a rollback plan, feature flags, or phased migration approach.',
|
|
268
|
+
undefined,
|
|
269
|
+
'breaking_without_mitigation',
|
|
270
|
+
),
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// No verification/testing mentioned
|
|
275
|
+
if (plan.tasks.length > 0 && !containsAny(allText, VERIFICATION_KEYWORDS)) {
|
|
276
|
+
gaps.push(
|
|
277
|
+
gap(
|
|
278
|
+
'minor',
|
|
279
|
+
'risk',
|
|
280
|
+
'No verification or testing mentioned in the plan.',
|
|
281
|
+
'Add at least one task or note about testing/validation.',
|
|
282
|
+
'tasks',
|
|
283
|
+
'no_verification_mentioned',
|
|
284
|
+
),
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
return gaps;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// ─── Pass 5: Clarity ─────────────────────────────────────────────
|
|
292
|
+
|
|
293
|
+
const AMBIGUOUS_WORDS = [
|
|
294
|
+
'maybe',
|
|
295
|
+
'perhaps',
|
|
296
|
+
'might',
|
|
297
|
+
'could',
|
|
298
|
+
'some',
|
|
299
|
+
'etc',
|
|
300
|
+
'soon',
|
|
301
|
+
'simple',
|
|
302
|
+
'easy',
|
|
303
|
+
'appropriate',
|
|
304
|
+
'various',
|
|
305
|
+
'several',
|
|
306
|
+
'probably',
|
|
307
|
+
'possibly',
|
|
308
|
+
'somehow',
|
|
309
|
+
];
|
|
310
|
+
|
|
311
|
+
function analyzeClarity(plan: Plan): PlanGap[] {
|
|
312
|
+
const gaps: PlanGap[] = [];
|
|
313
|
+
const allText = `${plan.objective} ${plan.scope} ${plan.decisions.join(' ')}`;
|
|
314
|
+
const lower = allText.toLowerCase();
|
|
315
|
+
|
|
316
|
+
// Ambiguous language
|
|
317
|
+
const found = AMBIGUOUS_WORDS.filter((w) => {
|
|
318
|
+
const regex = new RegExp(`\\b${w}\\b`, 'i');
|
|
319
|
+
return regex.test(lower);
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
if (found.length > 0) {
|
|
323
|
+
gaps.push(
|
|
324
|
+
gap(
|
|
325
|
+
'minor',
|
|
326
|
+
'clarity',
|
|
327
|
+
`Ambiguous language detected: ${found.slice(0, 5).join(', ')}${found.length > 5 ? ` (+${found.length - 5} more)` : ''}.`,
|
|
328
|
+
'Replace vague terms with concrete, specific language.',
|
|
329
|
+
undefined,
|
|
330
|
+
`ambiguous_words:${found.join(',')}`,
|
|
331
|
+
),
|
|
332
|
+
);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// Tasks with very short or missing descriptions
|
|
336
|
+
const shortTasks = plan.tasks.filter(
|
|
337
|
+
(t) => !t.description || t.description.trim().length < 10,
|
|
338
|
+
);
|
|
339
|
+
if (shortTasks.length > 0) {
|
|
340
|
+
gaps.push(
|
|
341
|
+
gap(
|
|
342
|
+
'minor',
|
|
343
|
+
'clarity',
|
|
344
|
+
`${shortTasks.length} task(s) with very short descriptions: ${shortTasks.map((t) => t.id).join(', ')}.`,
|
|
345
|
+
'Add detailed descriptions to all tasks explaining what needs to be done.',
|
|
346
|
+
'tasks',
|
|
347
|
+
'short_task_descriptions',
|
|
348
|
+
),
|
|
349
|
+
);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
return gaps;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// ─── Pass 6: Semantic Quality ────────────────────────────────────
|
|
356
|
+
|
|
357
|
+
const GENERIC_OBJECTIVE_PATTERNS = [
|
|
358
|
+
/^(create|build|implement|add|make|do)\s+\w+$/i,
|
|
359
|
+
/^fix\s+\w+$/i,
|
|
360
|
+
/^update\s+\w+$/i,
|
|
361
|
+
];
|
|
362
|
+
|
|
363
|
+
const RATIONALE_INDICATORS = ['because', 'since', 'due to', 'in order to', 'so that', 'given that', 'as a result'];
|
|
364
|
+
const SHALLOW_INDICATORS = ['better', 'good', 'best', 'nice', 'great', 'improved'];
|
|
365
|
+
|
|
366
|
+
function analyzeSemanticQuality(plan: Plan): PlanGap[] {
|
|
367
|
+
const gaps: PlanGap[] = [];
|
|
368
|
+
|
|
369
|
+
// Generic/too-short objective
|
|
370
|
+
if (plan.objective) {
|
|
371
|
+
const words = plan.objective.trim().split(/\s+/);
|
|
372
|
+
const isGeneric = GENERIC_OBJECTIVE_PATTERNS.some((p) => p.test(plan.objective.trim()));
|
|
373
|
+
|
|
374
|
+
if (isGeneric || words.length < 5) {
|
|
375
|
+
gaps.push(
|
|
376
|
+
gap(
|
|
377
|
+
'major',
|
|
378
|
+
'semantic-quality',
|
|
379
|
+
`Objective is too generic${words.length < 5 ? ` (${words.length} words)` : ''}: "${plan.objective.trim()}".`,
|
|
380
|
+
'Expand the objective to describe the specific outcome, context, and constraints.',
|
|
381
|
+
'objective',
|
|
382
|
+
'generic_objective',
|
|
383
|
+
),
|
|
384
|
+
);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// Task granularity check (too few or too many)
|
|
389
|
+
if (plan.tasks.length > 0 && plan.tasks.length < 3) {
|
|
390
|
+
gaps.push(
|
|
391
|
+
gap(
|
|
392
|
+
'minor',
|
|
393
|
+
'semantic-quality',
|
|
394
|
+
`Only ${plan.tasks.length} task(s) — plan may lack sufficient breakdown.`,
|
|
395
|
+
'Break down the work into 3-15 well-defined tasks for better tracking.',
|
|
396
|
+
'tasks',
|
|
397
|
+
'too_few_tasks',
|
|
398
|
+
),
|
|
399
|
+
);
|
|
400
|
+
} else if (plan.tasks.length > 20) {
|
|
401
|
+
gaps.push(
|
|
402
|
+
gap(
|
|
403
|
+
'major',
|
|
404
|
+
'semantic-quality',
|
|
405
|
+
`${plan.tasks.length} tasks — plan scope may be too large.`,
|
|
406
|
+
'Split into multiple plans or consolidate related tasks to stay under 20.',
|
|
407
|
+
'tasks',
|
|
408
|
+
'too_many_tasks',
|
|
409
|
+
),
|
|
410
|
+
);
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
// Decisions with shallow rationale (uses "better/good" without "because/since")
|
|
414
|
+
for (let i = 0; i < plan.decisions.length; i++) {
|
|
415
|
+
const d = plan.decisions[i];
|
|
416
|
+
const hasShallow = containsAny(d, SHALLOW_INDICATORS);
|
|
417
|
+
const hasRationale = containsAny(d, RATIONALE_INDICATORS);
|
|
418
|
+
if (hasShallow && !hasRationale) {
|
|
419
|
+
gaps.push(
|
|
420
|
+
gap(
|
|
421
|
+
'minor',
|
|
422
|
+
'semantic-quality',
|
|
423
|
+
`Decision ${i + 1} uses subjective language without justification.`,
|
|
424
|
+
'Replace "better/good/best" with concrete reasoning using "because/since/due to".',
|
|
425
|
+
`decisions[${i}]`,
|
|
426
|
+
'shallow_rationale',
|
|
427
|
+
),
|
|
428
|
+
);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
// All task titles must be unique
|
|
433
|
+
const titleSet = new Set<string>();
|
|
434
|
+
const duplicates: string[] = [];
|
|
435
|
+
for (const t of plan.tasks) {
|
|
436
|
+
if (titleSet.has(t.title)) duplicates.push(t.title);
|
|
437
|
+
titleSet.add(t.title);
|
|
438
|
+
}
|
|
439
|
+
if (duplicates.length > 0) {
|
|
440
|
+
gaps.push(
|
|
441
|
+
gap(
|
|
442
|
+
'minor',
|
|
443
|
+
'semantic-quality',
|
|
444
|
+
`Duplicate task titles: ${[...new Set(duplicates)].join(', ')}.`,
|
|
445
|
+
'Give each task a unique, descriptive title.',
|
|
446
|
+
'tasks',
|
|
447
|
+
'duplicate_task_titles',
|
|
448
|
+
),
|
|
449
|
+
);
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
// No decisions at all for multi-task plans
|
|
453
|
+
if (plan.tasks.length >= 3 && plan.decisions.length === 0) {
|
|
454
|
+
gaps.push(
|
|
455
|
+
gap(
|
|
456
|
+
'major',
|
|
457
|
+
'semantic-quality',
|
|
458
|
+
`${plan.tasks.length} tasks but no decisions documented.`,
|
|
459
|
+
'Document key decisions and their rationale — at least 1 per 3 tasks.',
|
|
460
|
+
'decisions',
|
|
461
|
+
'no_decisions',
|
|
462
|
+
),
|
|
463
|
+
);
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
return gaps;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
// ─── Types ───────────────────────────────────────────────────────
|
|
470
|
+
|
|
471
|
+
/** A custom gap analysis pass that agents can register. */
|
|
472
|
+
export type GapAnalysisPass = (plan: Plan) => PlanGap[];
|
|
473
|
+
|
|
474
|
+
export interface GapAnalysisOptions {
|
|
475
|
+
/** Custom gap analysis passes appended after the 6 built-in passes. */
|
|
476
|
+
customPasses?: GapAnalysisPass[];
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
// ─── Orchestrator ────────────────────────────────────────────────
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* Run all 6 built-in gap analysis passes on a plan, plus any custom passes.
|
|
483
|
+
* Returns a combined list of all gaps found, ordered by pass.
|
|
484
|
+
*
|
|
485
|
+
* @param plan - The plan to analyze
|
|
486
|
+
* @param options - Optional config with custom passes for domain-specific checks
|
|
487
|
+
*/
|
|
488
|
+
export function runGapAnalysis(plan: Plan, options?: GapAnalysisOptions): PlanGap[] {
|
|
489
|
+
const gaps = [
|
|
490
|
+
...analyzeStructure(plan),
|
|
491
|
+
...analyzeCompleteness(plan),
|
|
492
|
+
...analyzeFeasibility(plan),
|
|
493
|
+
...analyzeRisk(plan),
|
|
494
|
+
...analyzeClarity(plan),
|
|
495
|
+
...analyzeSemanticQuality(plan),
|
|
496
|
+
];
|
|
497
|
+
|
|
498
|
+
// Run custom passes (domain-specific checks like tool-feasibility, UI context, etc.)
|
|
499
|
+
if (options?.customPasses) {
|
|
500
|
+
for (const pass of options.customPasses) {
|
|
501
|
+
gaps.push(...pass(plan));
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
return gaps;
|
|
506
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gap analysis types and scoring constants.
|
|
3
|
+
* Ported from Salvador MCP's multi-pass grading engine.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// ─── Severity & Category ─────────────────────────────────────────
|
|
7
|
+
|
|
8
|
+
export type GapSeverity = 'critical' | 'major' | 'minor' | 'info';
|
|
9
|
+
|
|
10
|
+
export type GapCategory =
|
|
11
|
+
| 'structure'
|
|
12
|
+
| 'completeness'
|
|
13
|
+
| 'feasibility'
|
|
14
|
+
| 'risk'
|
|
15
|
+
| 'clarity'
|
|
16
|
+
| 'semantic-quality';
|
|
17
|
+
|
|
18
|
+
export interface PlanGap {
|
|
19
|
+
id: string;
|
|
20
|
+
severity: GapSeverity;
|
|
21
|
+
category: GapCategory;
|
|
22
|
+
description: string;
|
|
23
|
+
recommendation: string;
|
|
24
|
+
/** Where in the plan this gap was found (e.g. 'objective', 'tasks[2]'). */
|
|
25
|
+
location?: string;
|
|
26
|
+
/** Machine-readable condition that fired — debug aid only. */
|
|
27
|
+
_trigger?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// ─── Scoring Constants ───────────────────────────────────────────
|
|
31
|
+
|
|
32
|
+
/** Points deducted per gap severity. */
|
|
33
|
+
export const SEVERITY_WEIGHTS: Record<GapSeverity, number> = {
|
|
34
|
+
critical: 30,
|
|
35
|
+
major: 15,
|
|
36
|
+
minor: 2,
|
|
37
|
+
info: 0,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Maximum deduction per category.
|
|
42
|
+
* Categories not listed here have NO cap — uncapped deductions.
|
|
43
|
+
*/
|
|
44
|
+
export const CATEGORY_PENALTY_CAPS: Record<string, number> = {
|
|
45
|
+
clarity: 10,
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// ─── Validation Thresholds ───────────────────────────────────────
|
|
49
|
+
|
|
50
|
+
export const MIN_OBJECTIVE_LENGTH = 10;
|
|
51
|
+
export const MIN_SCOPE_LENGTH = 10;
|
|
52
|
+
export const MIN_DECISION_LENGTH = 10;
|
|
53
|
+
|
|
54
|
+
// ─── Helpers ─────────────────────────────────────────────────────
|
|
55
|
+
|
|
56
|
+
export function generateGapId(): string {
|
|
57
|
+
return `gap_${Date.now()}_${Math.random().toString(36).substring(2, 8)}`;
|
|
58
|
+
}
|