cbrowser 16.5.0 → 16.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -4
- package/dist/cli.js +169 -0
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/mcp-server-remote.d.ts.map +1 -1
- package/dist/mcp-server-remote.js +119 -0
- package/dist/mcp-server-remote.js.map +1 -1
- package/dist/mcp-server.d.ts.map +1 -1
- package/dist/mcp-server.js +119 -1
- package/dist/mcp-server.js.map +1 -1
- package/dist/persona-questionnaire.d.ts +74 -0
- package/dist/persona-questionnaire.d.ts.map +1 -0
- package/dist/persona-questionnaire.js +1629 -0
- package/dist/persona-questionnaire.js.map +1 -0
- package/docs/GETTING-STARTED.md +226 -0
- package/docs/MCP-INTEGRATION.md +295 -0
- package/docs/PERSONA-QUESTIONNAIRE.md +322 -0
- package/docs/README.md +74 -0
- package/examples/persona-questionnaire.ts +219 -0
- package/package.json +1 -1
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
# Persona Questionnaire System
|
|
2
|
+
|
|
3
|
+
**Introduced in v16.6.0**
|
|
4
|
+
|
|
5
|
+
The Persona Questionnaire system provides research-backed trait mapping for creating custom cognitive personas. Instead of defaulting traits to 0.5 (neutral baseline), this system uses behavioral questions to derive differentiated trait profiles.
|
|
6
|
+
|
|
7
|
+
## The Problem
|
|
8
|
+
|
|
9
|
+
When creating custom personas, AI-generated profiles often defaulted many traits to 0.5. This creates "average" personas that don't accurately represent real user diversity.
|
|
10
|
+
|
|
11
|
+
## The Solution
|
|
12
|
+
|
|
13
|
+
The questionnaire system:
|
|
14
|
+
1. Maps behavioral answers to trait values (0-1 scale)
|
|
15
|
+
2. Uses 5 distinct behavioral levels per trait (0, 0.25, 0.5, 0.75, 1.0)
|
|
16
|
+
3. Applies research-backed correlations between traits
|
|
17
|
+
4. Provides behavioral descriptions based on academic research
|
|
18
|
+
|
|
19
|
+
## Quick Start
|
|
20
|
+
|
|
21
|
+
### CLI Usage
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
# Interactive 8-question questionnaire
|
|
25
|
+
npx cbrowser persona-questionnaire start
|
|
26
|
+
|
|
27
|
+
# Comprehensive 25-trait questionnaire
|
|
28
|
+
npx cbrowser persona-questionnaire start --comprehensive --name "my-persona"
|
|
29
|
+
|
|
30
|
+
# Look up trait behavior at specific value
|
|
31
|
+
npx cbrowser persona-questionnaire lookup --trait patience --value 0.25
|
|
32
|
+
|
|
33
|
+
# List all available traits
|
|
34
|
+
npx cbrowser persona-questionnaire list-traits
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Programmatic Usage
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
import {
|
|
41
|
+
generatePersonaQuestionnaire,
|
|
42
|
+
buildTraitsFromAnswers,
|
|
43
|
+
getTraitBehaviors,
|
|
44
|
+
getTraitLabel,
|
|
45
|
+
} from 'cbrowser';
|
|
46
|
+
|
|
47
|
+
// Generate questionnaire
|
|
48
|
+
const questionnaire = generatePersonaQuestionnaire({ comprehensive: false });
|
|
49
|
+
|
|
50
|
+
// Build traits from answers
|
|
51
|
+
const traits = buildTraitsFromAnswers({
|
|
52
|
+
patience: 0.25,
|
|
53
|
+
riskTolerance: 0.75,
|
|
54
|
+
curiosity: 1.0,
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// Look up specific trait behavior
|
|
58
|
+
const behaviors = getTraitBehaviors('patience', 0.25);
|
|
59
|
+
console.log(behaviors.label); // "Low"
|
|
60
|
+
console.log(behaviors.behaviors); // ["Gets frustrated quickly", ...]
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### MCP Tools
|
|
64
|
+
|
|
65
|
+
Three MCP tools are available:
|
|
66
|
+
|
|
67
|
+
| Tool | Description |
|
|
68
|
+
|------|-------------|
|
|
69
|
+
| `persona_questionnaire_get` | Generate questionnaire questions |
|
|
70
|
+
| `persona_questionnaire_build` | Build trait profile from answers |
|
|
71
|
+
| `persona_trait_lookup` | Look up behaviors for trait value |
|
|
72
|
+
|
|
73
|
+
## The 25 Cognitive Traits
|
|
74
|
+
|
|
75
|
+
| Trait | Research Basis | What It Models |
|
|
76
|
+
|-------|---------------|----------------|
|
|
77
|
+
| **patience** | UX research | Time before abandoning on friction |
|
|
78
|
+
| **riskTolerance** | Prospect theory | Willingness to try unfamiliar actions |
|
|
79
|
+
| **comprehension** | Cognitive load theory | UI pattern understanding |
|
|
80
|
+
| **persistence** | Motivation research | Retry behavior after failures |
|
|
81
|
+
| **curiosity** | Exploration theory | Feature discovery tendency |
|
|
82
|
+
| **workingMemory** | Cognitive psychology | Multi-step task handling |
|
|
83
|
+
| **readingTendency** | Eye-tracking studies | Text consumption behavior |
|
|
84
|
+
| **resilience** | Positive psychology | Bounce-back from errors |
|
|
85
|
+
| **selfEfficacy** | Bandura (1977) | Belief in problem-solving ability |
|
|
86
|
+
| **satisficing** | Simon (1956) | Accept "good enough" vs optimize |
|
|
87
|
+
| **trustCalibration** | Fogg (2003) | Trust in unfamiliar interfaces |
|
|
88
|
+
| **interruptRecovery** | Mark et al. (2005) | Resume after distractions |
|
|
89
|
+
| **decisionFatigue** | Baumeister | Decision quality over time |
|
|
90
|
+
| **internalAttribution** | Attribution theory | Self-blame for failures |
|
|
91
|
+
| **externalAttribution** | Attribution theory | System-blame for failures |
|
|
92
|
+
| **techSavviness** | Digital literacy | Familiarity with UI patterns |
|
|
93
|
+
| **attentionSpan** | Attention research | Focus duration |
|
|
94
|
+
| **impulsivity** | Behavioral psychology | Quick vs deliberate actions |
|
|
95
|
+
| **errorRecovery** | Human factors | Speed of correcting mistakes |
|
|
96
|
+
| **visualProcessing** | Cognitive science | Image vs text preference |
|
|
97
|
+
| **spatialMemory** | Navigation research | UI layout recall |
|
|
98
|
+
| **patternRecognition** | Expertise research | UI element identification |
|
|
99
|
+
| **riskPerception** | Risk psychology | Danger assessment |
|
|
100
|
+
| **socialProof** | Cialdini (1984) | Influence of others' actions |
|
|
101
|
+
| **authorityTrust** | Trust research | Trust in official sources |
|
|
102
|
+
|
|
103
|
+
## Trait Reference Matrix
|
|
104
|
+
|
|
105
|
+
Each trait has 5 behavioral levels with specific descriptions:
|
|
106
|
+
|
|
107
|
+
### Example: Patience Trait
|
|
108
|
+
|
|
109
|
+
| Value | Label | Behaviors |
|
|
110
|
+
|-------|-------|-----------|
|
|
111
|
+
| 0 | Very Low | Abandons at first sign of friction, expects instant results |
|
|
112
|
+
| 0.25 | Low | Gets frustrated quickly, skips slow-loading content |
|
|
113
|
+
| 0.5 | Moderate | Waits reasonable time, tolerates some friction |
|
|
114
|
+
| 0.75 | High | Patient with delays, reads loading messages |
|
|
115
|
+
| 1.0 | Very High | Extremely patient, waits through any delay |
|
|
116
|
+
|
|
117
|
+
### Example: Self-Efficacy Trait
|
|
118
|
+
|
|
119
|
+
| Value | Label | Behaviors |
|
|
120
|
+
|-------|-------|-----------|
|
|
121
|
+
| 0 | Very Low | "I can't do this", gives up immediately on challenge |
|
|
122
|
+
| 0.25 | Low | Doubts ability, abandons 40% faster than average |
|
|
123
|
+
| 0.5 | Moderate | Normal confidence, persists through minor challenges |
|
|
124
|
+
| 0.75 | High | Confident problem-solver, sees obstacles as puzzles |
|
|
125
|
+
| 1.0 | Very High | "I'll figure this out", never attributes failure to self |
|
|
126
|
+
|
|
127
|
+
## Trait Correlations
|
|
128
|
+
|
|
129
|
+
The system automatically applies research-backed correlations:
|
|
130
|
+
|
|
131
|
+
| Primary Trait | Correlated Trait | Relationship |
|
|
132
|
+
|---------------|------------------|--------------|
|
|
133
|
+
| Low selfEfficacy | High internalAttribution | Self-blame for failures |
|
|
134
|
+
| Low selfEfficacy | Low resilience | Slower bounce-back |
|
|
135
|
+
| Low patience | Low resilience | Less tolerance for errors |
|
|
136
|
+
| High curiosity | Higher exploration | More feature discovery |
|
|
137
|
+
| Low trustCalibration | Longer evaluation time | Scrutinizes CTAs |
|
|
138
|
+
|
|
139
|
+
## Questionnaire Formats
|
|
140
|
+
|
|
141
|
+
### Quick Questionnaire (8 traits)
|
|
142
|
+
|
|
143
|
+
Core traits for basic persona differentiation:
|
|
144
|
+
- patience, riskTolerance, comprehension, persistence
|
|
145
|
+
- curiosity, workingMemory, readingTendency, resilience
|
|
146
|
+
|
|
147
|
+
### Comprehensive Questionnaire (25 traits)
|
|
148
|
+
|
|
149
|
+
All cognitive traits for detailed behavioral modeling.
|
|
150
|
+
|
|
151
|
+
### Custom Selection
|
|
152
|
+
|
|
153
|
+
Request specific traits:
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
const questionnaire = generatePersonaQuestionnaire({
|
|
157
|
+
traits: ['patience', 'selfEfficacy', 'trustCalibration'],
|
|
158
|
+
});
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## AskUserQuestion Integration
|
|
162
|
+
|
|
163
|
+
For Claude sessions, use the `formatForAskUserQuestion` function:
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
import { formatForAskUserQuestion, generatePersonaQuestionnaire } from 'cbrowser';
|
|
167
|
+
|
|
168
|
+
const questionnaire = generatePersonaQuestionnaire({ comprehensive: false });
|
|
169
|
+
const askUserFormat = formatForAskUserQuestion(questionnaire.questions);
|
|
170
|
+
|
|
171
|
+
// Returns format compatible with Claude's AskUserQuestion tool:
|
|
172
|
+
// {
|
|
173
|
+
// questions: [
|
|
174
|
+
// {
|
|
175
|
+
// question: "How does this user handle waiting?",
|
|
176
|
+
// header: "patience",
|
|
177
|
+
// options: [
|
|
178
|
+
// { label: "Very impatient", description: "Abandons at first delay" },
|
|
179
|
+
// ...
|
|
180
|
+
// ],
|
|
181
|
+
// multiSelect: false
|
|
182
|
+
// },
|
|
183
|
+
// ...
|
|
184
|
+
// ]
|
|
185
|
+
// }
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
## CLI Interactive Mode
|
|
189
|
+
|
|
190
|
+
The CLI provides an interactive questionnaire experience:
|
|
191
|
+
|
|
192
|
+
```bash
|
|
193
|
+
$ npx cbrowser persona-questionnaire start --name "anxious-newbie"
|
|
194
|
+
|
|
195
|
+
=== CBrowser Persona Questionnaire ===
|
|
196
|
+
Creating persona: anxious-newbie (8 core traits)
|
|
197
|
+
|
|
198
|
+
[1/8] Patience
|
|
199
|
+
How does this user handle waiting for pages or actions?
|
|
200
|
+
1. Very impatient - abandons at first delay
|
|
201
|
+
2. Somewhat impatient - frustrated by normal load times
|
|
202
|
+
3. Average - tolerates reasonable waits
|
|
203
|
+
4. Patient - waits through delays calmly
|
|
204
|
+
5. Very patient - unlimited patience
|
|
205
|
+
> 2
|
|
206
|
+
|
|
207
|
+
[2/8] Risk Tolerance
|
|
208
|
+
How willing is this user to try unfamiliar features?
|
|
209
|
+
...
|
|
210
|
+
|
|
211
|
+
=== Persona Created ===
|
|
212
|
+
Saved to: ~/.cbrowser/personas/anxious-newbie.json
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
## Using Custom Personas
|
|
216
|
+
|
|
217
|
+
After creating a persona via questionnaire:
|
|
218
|
+
|
|
219
|
+
```typescript
|
|
220
|
+
import { runCognitiveJourney } from 'cbrowser';
|
|
221
|
+
|
|
222
|
+
const result = await runCognitiveJourney({
|
|
223
|
+
persona: 'anxious-newbie', // Uses saved persona
|
|
224
|
+
startUrl: 'https://example.com',
|
|
225
|
+
goal: 'complete signup',
|
|
226
|
+
});
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
Or with inline traits:
|
|
230
|
+
|
|
231
|
+
```typescript
|
|
232
|
+
const customTraits = buildTraitsFromAnswers({
|
|
233
|
+
patience: 0.25,
|
|
234
|
+
selfEfficacy: 0.25,
|
|
235
|
+
trustCalibration: 0.25,
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
const result = await runCognitiveJourney({
|
|
239
|
+
persona: 'custom',
|
|
240
|
+
customTraits,
|
|
241
|
+
startUrl: 'https://example.com',
|
|
242
|
+
goal: 'complete signup',
|
|
243
|
+
});
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
## Research Citations
|
|
247
|
+
|
|
248
|
+
The trait system is grounded in academic research:
|
|
249
|
+
|
|
250
|
+
- **Bandura, A. (1977)** - Self-Efficacy: Toward a Unifying Theory of Behavioral Change
|
|
251
|
+
- **Kahneman, D. & Tversky, A.** - Prospect Theory and Decision Making
|
|
252
|
+
- **Simon, H. (1956)** - Satisficing and Administrative Behavior
|
|
253
|
+
- **Fogg, B.J. (2003)** - Persuasive Technology and Trust
|
|
254
|
+
- **Mark, G. et al. (2005)** - No Task Left Behind: Interrupt Recovery
|
|
255
|
+
- **Baumeister, R.** - Ego Depletion and Decision Fatigue
|
|
256
|
+
- **Nielsen, J.** - Usability Engineering and User Behavior
|
|
257
|
+
- **Cialdini, R. (1984)** - Influence: The Psychology of Persuasion
|
|
258
|
+
|
|
259
|
+
## API Reference
|
|
260
|
+
|
|
261
|
+
### generatePersonaQuestionnaire(options)
|
|
262
|
+
|
|
263
|
+
Generate questionnaire questions.
|
|
264
|
+
|
|
265
|
+
```typescript
|
|
266
|
+
interface QuestionnaireOptions {
|
|
267
|
+
comprehensive?: boolean; // All 25 traits (default: false = 8 traits)
|
|
268
|
+
traits?: string[]; // Specific traits to include
|
|
269
|
+
includeResearch?: boolean; // Include research citations
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
const questionnaire = generatePersonaQuestionnaire(options);
|
|
273
|
+
// Returns: { questions: Question[], estimatedMinutes: number }
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
### buildTraitsFromAnswers(answers)
|
|
277
|
+
|
|
278
|
+
Build complete trait profile from questionnaire answers.
|
|
279
|
+
|
|
280
|
+
```typescript
|
|
281
|
+
const traits = buildTraitsFromAnswers({
|
|
282
|
+
patience: 0.25,
|
|
283
|
+
curiosity: 0.75,
|
|
284
|
+
});
|
|
285
|
+
// Returns: CognitiveTraits with correlations applied
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
### getTraitBehaviors(trait, value)
|
|
289
|
+
|
|
290
|
+
Get behavioral description for a trait value.
|
|
291
|
+
|
|
292
|
+
```typescript
|
|
293
|
+
const behaviors = getTraitBehaviors('patience', 0.25);
|
|
294
|
+
// Returns: { label: string, description: string, behaviors: string[] }
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
### getTraitLabel(trait, value)
|
|
298
|
+
|
|
299
|
+
Get short label for trait value.
|
|
300
|
+
|
|
301
|
+
```typescript
|
|
302
|
+
const label = getTraitLabel('patience', 0.25);
|
|
303
|
+
// Returns: "Low"
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
### getTraitReference(trait)
|
|
307
|
+
|
|
308
|
+
Get full research reference for a trait.
|
|
309
|
+
|
|
310
|
+
```typescript
|
|
311
|
+
const ref = getTraitReference('selfEfficacy');
|
|
312
|
+
// Returns: { researchBasis: string, citations: string[], levels: Level[] }
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
### formatForAskUserQuestion(questions)
|
|
316
|
+
|
|
317
|
+
Format questions for Claude's AskUserQuestion tool.
|
|
318
|
+
|
|
319
|
+
```typescript
|
|
320
|
+
const formatted = formatForAskUserQuestion(questions);
|
|
321
|
+
// Returns: { questions: AskUserQuestion[] }
|
|
322
|
+
```
|
package/docs/README.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# CBrowser Documentation
|
|
2
|
+
|
|
3
|
+
Welcome to the CBrowser documentation. This directory contains comprehensive guides for all CBrowser features.
|
|
4
|
+
|
|
5
|
+
## Quick Links
|
|
6
|
+
|
|
7
|
+
| Guide | Description |
|
|
8
|
+
|-------|-------------|
|
|
9
|
+
| [Getting Started](./GETTING-STARTED.md) | Installation, first commands, basic usage |
|
|
10
|
+
| [Cognitive Simulation](./COGNITIVE-SIMULATION.md) | User simulation, personas, trait system |
|
|
11
|
+
| [Persona Questionnaire](./PERSONA-QUESTIONNAIRE.md) | Research-backed custom persona creation |
|
|
12
|
+
| [Visual Testing](./VISUAL-TESTING.md) | AI visual regression, cross-browser, responsive |
|
|
13
|
+
| [MCP Integration](./MCP-INTEGRATION.md) | Claude Desktop and remote MCP server setup |
|
|
14
|
+
| [Natural Language Tests](./NATURAL-LANGUAGE-TESTS.md) | Writing tests in plain English |
|
|
15
|
+
| [Constitutional Safety](./CONSTITUTIONAL-SAFETY.md) | Risk classification and safety zones |
|
|
16
|
+
| [CLI Reference](./CLI-REFERENCE.md) | Complete command-line reference |
|
|
17
|
+
| [API Reference](./API-REFERENCE.md) | TypeScript API documentation |
|
|
18
|
+
|
|
19
|
+
## Feature Guides
|
|
20
|
+
|
|
21
|
+
### Core Features
|
|
22
|
+
- [Self-Healing Selectors](./SELF-HEALING-SELECTORS.md) - ARIA-first selector strategy
|
|
23
|
+
- [Agent-Ready Audit](./AGENT-READY-AUDIT.md) - AI-agent friendliness analysis
|
|
24
|
+
- [Competitive Benchmark](./COMPETITIVE-BENCHMARK.md) - UX comparison across sites
|
|
25
|
+
- [Empathy Audit](./EMPATHY-AUDIT.md) - Disability simulation testing
|
|
26
|
+
|
|
27
|
+
### Testing Features
|
|
28
|
+
- [Test Suites](./TEST-SUITES.md) - Natural language test execution
|
|
29
|
+
- [Test Repair](./TEST-REPAIR.md) - AI-powered test fixing
|
|
30
|
+
- [Flaky Detection](./FLAKY-DETECTION.md) - Identify unreliable tests
|
|
31
|
+
- [Coverage Mapping](./COVERAGE-MAPPING.md) - Find untested pages
|
|
32
|
+
|
|
33
|
+
### Visual Features
|
|
34
|
+
- [Visual Baselines](./VISUAL-BASELINES.md) - Capture and compare screenshots
|
|
35
|
+
- [Cross-Browser Testing](./CROSS-BROWSER-TESTING.md) - Chrome, Firefox, Safari comparison
|
|
36
|
+
- [Responsive Testing](./RESPONSIVE-TESTING.md) - Mobile, tablet, desktop viewports
|
|
37
|
+
- [A/B Comparison](./AB-COMPARISON.md) - Compare two URLs visually
|
|
38
|
+
|
|
39
|
+
### Advanced Features
|
|
40
|
+
- [Chaos Testing](./CHAOS-TESTING.md) - Inject failures, test resilience
|
|
41
|
+
- [Bug Hunting](./BUG-HUNTING.md) - Autonomous issue discovery
|
|
42
|
+
- [Performance Testing](./PERFORMANCE-TESTING.md) - Regression detection
|
|
43
|
+
- [Session Management](./SESSION-MANAGEMENT.md) - Save and restore browser state
|
|
44
|
+
|
|
45
|
+
## MCP Tools Reference
|
|
46
|
+
|
|
47
|
+
CBrowser provides 48 MCP tools organized by category:
|
|
48
|
+
|
|
49
|
+
| Category | Tools | Description |
|
|
50
|
+
|----------|-------|-------------|
|
|
51
|
+
| **Navigation** | 5 | Navigate, screenshot, extract, cloudflare detection |
|
|
52
|
+
| **Interaction** | 4 | Click, smart click, fill, scroll |
|
|
53
|
+
| **Testing** | 3 | Test suites, repair, flaky detection |
|
|
54
|
+
| **Visual** | 6 | Baselines, regression, cross-browser, responsive, A/B |
|
|
55
|
+
| **Cognitive** | 3 | Journey init, state update, persona comparison |
|
|
56
|
+
| **Persona** | 3 | Questionnaire, build, trait lookup |
|
|
57
|
+
| **Analysis** | 5 | Bug hunt, chaos, agent audit, benchmark, empathy |
|
|
58
|
+
| **Stealth** | 5 | Enable, disable, status, check, diagnose |
|
|
59
|
+
|
|
60
|
+
See [MCP Integration](./MCP-INTEGRATION.md) for complete tool documentation.
|
|
61
|
+
|
|
62
|
+
## Version History
|
|
63
|
+
|
|
64
|
+
See [CHANGELOG.md](../CHANGELOG.md) for detailed release notes.
|
|
65
|
+
|
|
66
|
+
### Current Version: 16.7.0
|
|
67
|
+
|
|
68
|
+
Key features:
|
|
69
|
+
- 48 MCP tools for Claude integration
|
|
70
|
+
- Research-backed persona questionnaire system
|
|
71
|
+
- 25 cognitive traits with behavioral mappings
|
|
72
|
+
- Accessibility empathy testing
|
|
73
|
+
- Competitive UX benchmarking
|
|
74
|
+
- Agent-ready site auditing
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Persona Questionnaire Example
|
|
3
|
+
*
|
|
4
|
+
* This example demonstrates the research-backed persona questionnaire system
|
|
5
|
+
* introduced in v16.6.0. The questionnaire maps behavioral answers to cognitive
|
|
6
|
+
* trait values (0-1 scale) with proper correlation adjustments.
|
|
7
|
+
*
|
|
8
|
+
* The questionnaire works across:
|
|
9
|
+
* - Claude sessions (via AskUserQuestion tool)
|
|
10
|
+
* - CLI (interactive terminal prompts)
|
|
11
|
+
* - Remote and Local MCP servers
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
generatePersonaQuestionnaire,
|
|
16
|
+
buildTraitsFromAnswers,
|
|
17
|
+
getTraitBehaviors,
|
|
18
|
+
getTraitLabel,
|
|
19
|
+
getTraitReference,
|
|
20
|
+
formatForAskUserQuestion,
|
|
21
|
+
TRAIT_REFERENCE_MATRIX,
|
|
22
|
+
} from 'cbrowser';
|
|
23
|
+
|
|
24
|
+
// Example 1: Generate the questionnaire for Claude's AskUserQuestion tool
|
|
25
|
+
function claudeQuestionnaireExample() {
|
|
26
|
+
console.log('\n=== Claude AskUserQuestion Format ===\n');
|
|
27
|
+
|
|
28
|
+
// Generate a quick 8-trait questionnaire
|
|
29
|
+
const questionnaire = generatePersonaQuestionnaire({ comprehensive: false });
|
|
30
|
+
|
|
31
|
+
console.log(`Generated ${questionnaire.questions.length} questions:`);
|
|
32
|
+
|
|
33
|
+
for (const q of questionnaire.questions) {
|
|
34
|
+
console.log(`\nTrait: ${q.trait}`);
|
|
35
|
+
console.log(`Question: ${q.question}`);
|
|
36
|
+
console.log('Options:');
|
|
37
|
+
for (const opt of q.options) {
|
|
38
|
+
console.log(` [${opt.value}] ${opt.label}`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Format for AskUserQuestion tool
|
|
43
|
+
const askUserFormat = formatForAskUserQuestion(questionnaire.questions.slice(0, 4));
|
|
44
|
+
console.log('\n=== AskUserQuestion Format (first 4 questions) ===');
|
|
45
|
+
console.log(JSON.stringify(askUserFormat, null, 2));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Example 2: Build traits from questionnaire answers
|
|
49
|
+
function buildTraitsExample() {
|
|
50
|
+
console.log('\n=== Building Traits from Answers ===\n');
|
|
51
|
+
|
|
52
|
+
// Simulate answers from questionnaire
|
|
53
|
+
const answers: Record<string, number> = {
|
|
54
|
+
patience: 0.25, // Gets frustrated quickly
|
|
55
|
+
riskTolerance: 0.75, // Willing to try new things
|
|
56
|
+
comprehension: 0.5, // Average
|
|
57
|
+
persistence: 0.75, // Keeps trying
|
|
58
|
+
curiosity: 1.0, // Very curious, explores everything
|
|
59
|
+
workingMemory: 0.5, // Average
|
|
60
|
+
readingTendency: 0.25, // Skims, doesn't read carefully
|
|
61
|
+
resilience: 0.5, // Average bounce-back
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// Build full trait profile with correlations applied
|
|
65
|
+
const traits = buildTraitsFromAnswers(answers);
|
|
66
|
+
|
|
67
|
+
console.log('Input answers:', answers);
|
|
68
|
+
console.log('\nDerived trait profile (with correlations):');
|
|
69
|
+
|
|
70
|
+
for (const [trait, value] of Object.entries(traits)) {
|
|
71
|
+
const label = getTraitLabel(trait, value);
|
|
72
|
+
console.log(` ${trait}: ${value.toFixed(2)} (${label})`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Example 3: Lookup trait behaviors
|
|
77
|
+
function traitBehaviorLookup() {
|
|
78
|
+
console.log('\n=== Trait Behavior Lookup ===\n');
|
|
79
|
+
|
|
80
|
+
const trait = 'patience';
|
|
81
|
+
const value = 0.25;
|
|
82
|
+
|
|
83
|
+
const behaviors = getTraitBehaviors(trait, value);
|
|
84
|
+
const reference = getTraitReference(trait);
|
|
85
|
+
|
|
86
|
+
console.log(`Trait: ${trait}`);
|
|
87
|
+
console.log(`Value: ${value}`);
|
|
88
|
+
console.log(`Label: ${behaviors.label}`);
|
|
89
|
+
console.log(`Description: ${behaviors.description}`);
|
|
90
|
+
console.log(`\nBehaviors:`);
|
|
91
|
+
for (const behavior of behaviors.behaviors) {
|
|
92
|
+
console.log(` - ${behavior}`);
|
|
93
|
+
}
|
|
94
|
+
console.log(`\nResearch basis: ${reference?.researchBasis || 'None'}`);
|
|
95
|
+
console.log(`Citations: ${reference?.citations?.join(', ') || 'None'}`);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Example 4: List all available traits
|
|
99
|
+
function listAllTraits() {
|
|
100
|
+
console.log('\n=== All 25 Cognitive Traits ===\n');
|
|
101
|
+
|
|
102
|
+
const traits = Object.keys(TRAIT_REFERENCE_MATRIX);
|
|
103
|
+
|
|
104
|
+
console.log(`Total traits: ${traits.length}\n`);
|
|
105
|
+
|
|
106
|
+
for (const trait of traits) {
|
|
107
|
+
const ref = getTraitReference(trait);
|
|
108
|
+
console.log(`${trait}:`);
|
|
109
|
+
console.log(` Research: ${ref?.researchBasis || 'General'}`);
|
|
110
|
+
console.log(` Range: 0 (${getTraitLabel(trait, 0)}) to 1 (${getTraitLabel(trait, 1)})`);
|
|
111
|
+
console.log('');
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Example 5: Comprehensive questionnaire (all 25 traits)
|
|
116
|
+
function comprehensiveQuestionnaireExample() {
|
|
117
|
+
console.log('\n=== Comprehensive Questionnaire ===\n');
|
|
118
|
+
|
|
119
|
+
const questionnaire = generatePersonaQuestionnaire({
|
|
120
|
+
comprehensive: true,
|
|
121
|
+
includeResearch: true,
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
console.log(`Comprehensive questionnaire: ${questionnaire.questions.length} questions`);
|
|
125
|
+
console.log(`Estimated time: ${questionnaire.estimatedMinutes} minutes\n`);
|
|
126
|
+
|
|
127
|
+
// Show first 3 questions with research citations
|
|
128
|
+
for (const q of questionnaire.questions.slice(0, 3)) {
|
|
129
|
+
console.log(`[${q.trait}] ${q.question}`);
|
|
130
|
+
if (q.researchBasis) {
|
|
131
|
+
console.log(` Research: ${q.researchBasis}`);
|
|
132
|
+
}
|
|
133
|
+
console.log('');
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Example 6: Custom trait selection
|
|
138
|
+
function customTraitSelection() {
|
|
139
|
+
console.log('\n=== Custom Trait Selection ===\n');
|
|
140
|
+
|
|
141
|
+
// Only get questions for specific traits
|
|
142
|
+
const questionnaire = generatePersonaQuestionnaire({
|
|
143
|
+
traits: ['patience', 'riskTolerance', 'selfEfficacy', 'trustCalibration'],
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
console.log(`Custom questionnaire: ${questionnaire.questions.length} questions\n`);
|
|
147
|
+
|
|
148
|
+
for (const q of questionnaire.questions) {
|
|
149
|
+
console.log(`${q.trait}: ${q.question}`);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Example 7: Trait correlation demonstration
|
|
154
|
+
function correlationExample() {
|
|
155
|
+
console.log('\n=== Trait Correlations ===\n');
|
|
156
|
+
|
|
157
|
+
// Low self-efficacy should correlate with higher internal attribution
|
|
158
|
+
const lowEfficacyAnswers: Record<string, number> = {
|
|
159
|
+
selfEfficacy: 0.25, // "I probably can't figure this out"
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const derived = buildTraitsFromAnswers(lowEfficacyAnswers);
|
|
163
|
+
|
|
164
|
+
console.log('Input: selfEfficacy = 0.25 (Low)');
|
|
165
|
+
console.log('\nCorrelated traits automatically adjusted:');
|
|
166
|
+
console.log(` internalAttribution: ${derived.internalAttribution?.toFixed(2)} (blames self for failures)`);
|
|
167
|
+
console.log(` resilience: ${derived.resilience?.toFixed(2)} (lower bounce-back ability)`);
|
|
168
|
+
console.log('\nResearch: Bandura (1977) - Self-efficacy affects attribution patterns');
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Example 8: Integration with cognitive journey
|
|
172
|
+
async function journeyIntegrationExample() {
|
|
173
|
+
console.log('\n=== Integration with Cognitive Journey ===\n');
|
|
174
|
+
|
|
175
|
+
// Build traits from questionnaire answers
|
|
176
|
+
const answers: Record<string, number> = {
|
|
177
|
+
patience: 0.25,
|
|
178
|
+
riskTolerance: 0.5,
|
|
179
|
+
comprehension: 0.75,
|
|
180
|
+
selfEfficacy: 0.5,
|
|
181
|
+
curiosity: 0.75,
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
const traits = buildTraitsFromAnswers(answers);
|
|
185
|
+
|
|
186
|
+
console.log('Generated trait profile for cognitive journey:');
|
|
187
|
+
console.log(JSON.stringify(traits, null, 2));
|
|
188
|
+
|
|
189
|
+
console.log('\nUse with runCognitiveJourney:');
|
|
190
|
+
console.log(`
|
|
191
|
+
const result = await runCognitiveJourney({
|
|
192
|
+
persona: 'custom',
|
|
193
|
+
startUrl: 'https://example.com',
|
|
194
|
+
goal: 'complete signup',
|
|
195
|
+
customTraits: ${JSON.stringify(traits, null, 2)},
|
|
196
|
+
});
|
|
197
|
+
`);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Run examples
|
|
201
|
+
async function main() {
|
|
202
|
+
console.log('╔════════════════════════════════════════════════════════════════╗');
|
|
203
|
+
console.log('║ CBrowser Persona Questionnaire Examples (v16.6.0) ║');
|
|
204
|
+
console.log('║ Research-backed trait mapping for cognitive user simulation ║');
|
|
205
|
+
console.log('╚════════════════════════════════════════════════════════════════╝');
|
|
206
|
+
|
|
207
|
+
claudeQuestionnaireExample();
|
|
208
|
+
buildTraitsExample();
|
|
209
|
+
traitBehaviorLookup();
|
|
210
|
+
// listAllTraits(); // Uncomment for full trait list
|
|
211
|
+
comprehensiveQuestionnaireExample();
|
|
212
|
+
customTraitSelection();
|
|
213
|
+
correlationExample();
|
|
214
|
+
await journeyIntegrationExample();
|
|
215
|
+
|
|
216
|
+
console.log('\n=== Example Complete ===');
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
main().catch(console.error);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cbrowser",
|
|
3
|
-
"version": "16.
|
|
3
|
+
"version": "16.7.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Cognitive browser automation that thinks like your users. Simulate real user cognition with abandonment detection, constitutional safety, chaos engineering, and UX friction discovery.",
|
|
6
6
|
"main": "dist/index.js",
|