cbrowser 20.1.2 → 20.2.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.
@@ -23,7 +23,7 @@
23
23
  */
24
24
  import Anthropic from "@anthropic-ai/sdk";
25
25
  import { type AutoCaptureSetting } from "../recording/auto-capture.js";
26
- import type { CognitiveState, CognitiveJourneyResult, CognitiveTraits } from "../types.js";
26
+ import type { CognitiveState, CognitiveJourneyResult, Persona, CognitiveTraits } from "../types.js";
27
27
  import type { DecisionProvider } from "./journey-trace.js";
28
28
  /**
29
29
  * Get the Anthropic API key from environment or config file.
@@ -216,6 +216,36 @@ export interface CognitiveStep {
216
216
  url?: string;
217
217
  }
218
218
  export declare function runCognitiveJourney(options: CognitiveJourneyOptions): Promise<CognitiveJourneyResult>;
219
+ /**
220
+ * The journey's average confusion and peak frustration, over the state each
221
+ * step logged plus the final state for the peak. Both read only the final
222
+ * state before 20.1.3: the "average" added the final confusion once per
223
+ * friction point and divided by their count, and the "max" was the last
224
+ * frustration (2026-10-23). With no step logged, both are the final state's.
225
+ */
226
+ export declare function journeyEmotionSummary(steps: ReadonlyArray<{
227
+ confusion: number;
228
+ frustration: number;
229
+ }>, final: {
230
+ confusionLevel: number;
231
+ frustrationLevel: number;
232
+ }): {
233
+ avgConfusionLevel: number;
234
+ maxFrustrationLevel: number;
235
+ };
236
+ /**
237
+ * The persona a journey runs as.
238
+ *
239
+ * A known name resolves to its own record: built-in, custom and account
240
+ * personas through getPersona, and the accessibility and emotional ones
241
+ * (cognitive-adhd, anxious-user, ...) through getAnyPersona. Only getPersona
242
+ * was asked before 20.1.3, so a journey for any of those 15 personas, which is
243
+ * what empathy_audit starts, ran on traits generated from the name: 14 to 24 of
244
+ * their 25 traits differed from the persona's own (2026-10-23). A name nothing
245
+ * knows is still read as a description of the person, as `--persona` says. An
246
+ * agent persona is refused, because a journey simulates a person.
247
+ */
248
+ export declare function resolveJourneyPersona(name: string, customTraits?: Partial<CognitiveTraits>): Persona;
219
249
  /**
220
250
  * The live per-step decision: one messages.create call, its text blocks read
221
251
  * together, and one more ask for the JSON alone when the reply does not hold
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cognitive/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,SAAS,MAAM,mBAAmB,CAAC;AAI1C,OAAO,EAA8D,KAAK,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAMnI,OAAO,KAAK,EACV,cAAc,EAEd,sBAAsB,EAItB,eAAe,EAKhB,MAAM,aAAa,CAAC;AA4BrB,OAAO,KAAK,EAAE,gBAAgB,EAAe,MAAM,oBAAoB,CAAC;AAWxE;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,GAAG,IAAI,CAalD;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,CAO1C;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAkBvD;AAED;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,IAAI,CAa5C;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,OAAO,CAG5C;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,IAAI,OAAO,CAO7C;AAED;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,OAAO,CAE9C;AAkiBD,MAAM,WAAW,uBAAuB;IACtC,kCAAkC;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,oHAAoH;IACpH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,qCAAqC;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,mBAAmB;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,uCAAuC;IACvC,YAAY,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC;IACxC,mCAAmC;IACnC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,8BAA8B;IAC9B,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GAC1D;IAAE,iBAAiB,EAAE,MAAM,CAAC;IAAC,mBAAmB,EAAE,MAAM,CAAA;CAAE,CAS5D;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,OAAO,CA4DpG;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,UAAU,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,gBAAgB,CA6CzH;AAED,oFAAoF;AACpF,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEhD;AAMD;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAwClG;AAybD,OAAO,EACL,2BAA2B,EAC3B,qBAAqB,EACrB,qBAAqB,EACrB,aAAa,EACb,4BAA4B,EAC5B,4BAA4B,EAC5B,8BAA8B,EAC9B,sBAAsB,EACtB,yBAAyB,GAC1B,MAAM,eAAe,CAAC;AAMvB,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,YAAY,EACV,UAAU,EACV,QAAQ,EACR,OAAO,EACP,QAAQ,EACR,aAAa,EACb,UAAU,EACV,gBAAgB,GACjB,MAAM,iBAAiB,CAAC;AAMzB,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,aAAa,GACd,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EAAE,gBAAgB,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC"}
@@ -26,7 +26,8 @@ import { existsSync, readFileSync } from "fs";
26
26
  import { join } from "path";
27
27
  import { CBrowser } from "../browser.js";
28
28
  import { finishAutoCapture, resolveCaptureOptions, startAutoCapture } from "../recording/auto-capture.js";
29
- import { getPersona, getCognitiveProfile, createCognitivePersona, } from "../personas.js";
29
+ import { getPersona, getAnyPersona, getCognitiveProfile, createCognitivePersona, } from "../personas.js";
30
+ import { isAgentPersonaObject } from "../agent-personas.js";
30
31
  import { createInitialEmotionalState, createEmotionalConfig, applyEmotionalTrigger, decayEmotionsWithTraits, deriveSimplifiedState, calculateAbandonmentModifier, describeEmotionalState, shouldConsiderAbandonment, } from "./emotions.js";
31
32
  import { calculateFatigueIncrement, calculateFittsMovementTime, shouldSwitchToSystem2, canReturnToSystem1, calculateTypingTime, calculateScanWidthMultiplier, calculateGazeMouseLag, calculatePeripheralVision, createHabituationState, updateHabituationState, classifyUIPattern, } from "../types.js";
32
33
  import { loadConfigFile, getDataDir } from "../config.js";
@@ -703,58 +704,7 @@ export async function runCognitiveJourney(options) {
703
704
  const traceWriter = options.trace
704
705
  ? new JourneyTraceWriter(nameSlug ? { journeyId: `journey-${nameSlug}-${Date.now()}-${Math.random().toString(36).slice(2, 8)}` } : undefined)
705
706
  : null;
706
- // Get or create persona
707
- const existingPersona = getPersona(options.persona);
708
- let personaObj;
709
- if (!existingPersona) {
710
- personaObj = createCognitivePersona(options.persona, options.persona, options.customTraits || {});
711
- }
712
- else if (options.customTraits) {
713
- // v16.7.1: full default trait set (was only 7, causing trait dropout).
714
- // Said 25 until 2026-08-01; the model has 26.
715
- const defaultTraits = {
716
- // Required traits (7)
717
- patience: 0.5,
718
- riskTolerance: 0.5,
719
- comprehension: 0.5,
720
- persistence: 0.5,
721
- curiosity: 0.5,
722
- workingMemory: 0.5,
723
- readingTendency: 0.5,
724
- // Optional traits - Tier 1: Core
725
- resilience: 0.5,
726
- selfEfficacy: 0.5,
727
- satisficing: 0.5,
728
- trustCalibration: 0.5,
729
- interruptRecovery: 0.5,
730
- // Optional traits - Tier 2+
731
- informationForaging: 0.5,
732
- changeBlindness: 0.3,
733
- anchoringBias: 0.5,
734
- timeHorizon: 0.5,
735
- attributionStyle: 0.5,
736
- metacognitivePlanning: 0.5,
737
- proceduralFluency: 0.5,
738
- transferLearning: 0.5,
739
- authoritySensitivity: 0.5,
740
- emotionalContagion: 0.5,
741
- fearOfMissingOut: 0.5,
742
- socialProofSensitivity: 0.5,
743
- mentalModelFlexibility: 0.5,
744
- siteFamiliarity: 0.5,
745
- };
746
- personaObj = {
747
- ...existingPersona,
748
- cognitiveTraits: {
749
- ...defaultTraits,
750
- ...(existingPersona.cognitiveTraits || {}),
751
- ...options.customTraits,
752
- },
753
- };
754
- }
755
- else {
756
- personaObj = existingPersona;
757
- }
707
+ const personaObj = resolveJourneyPersona(options.persona, options.customTraits);
758
708
  const profile = getCognitiveProfile(personaObj);
759
709
  const traits = profile.traits;
760
710
  // Build the InputTraits subset used by human-input.ts. CognitiveTraits has
@@ -1197,7 +1147,13 @@ Right now it's ${temporalState.description}.`;
1197
1147
  const removedClickables = [...prevClickableTexts].filter(t => t && !currentTexts.has(t)).slice(0, 8);
1198
1148
  lastActionOutcome.newClickables = newClickables;
1199
1149
  lastActionOutcome.removedClickables = removedClickables;
1200
- lastActionOutcome.scrollDelta = viewportCtx.scroll.y - prevScrollY;
1150
+ // After a navigation the scroll position belongs to the new page, so the
1151
+ // difference is not a scroll: every link followed from partway down a
1152
+ // page was reported as "Scrolled up Npx" (2026-10-23). An in-page anchor
1153
+ // keeps its scroll.
1154
+ const pageOf = (u) => (u ?? "").split("#")[0];
1155
+ const navigated = lastActionOutcome.urlChanged && pageOf(lastActionOutcome.fromUrl) !== pageOf(lastActionOutcome.toUrl);
1156
+ lastActionOutcome.scrollDelta = navigated ? undefined : viewportCtx.scroll.y - prevScrollY;
1201
1157
  }
1202
1158
  prevClickableTexts = new Set(availableElements.map(e => e.text));
1203
1159
  prevScrollY = viewportCtx.scroll.y;
@@ -1777,6 +1733,11 @@ Right now it's ${temporalState.description}.`;
1777
1733
  target: parsed.actionTarget,
1778
1734
  success: result.success,
1779
1735
  });
1736
+ // A failed action in fast mode counts toward shouldSwitchToSystem2's
1737
+ // three-error rule. Nothing counted them, so the rule never fired
1738
+ // (2026-10-23).
1739
+ if (!result.success && state.cognitiveMode?.system === 1)
1740
+ state.cognitiveMode.system1Errors++;
1780
1741
  // Track page visits if URL changed
1781
1742
  const urlChanged = !!result.newUrl && result.newUrl !== _urlBeforeAction;
1782
1743
  // Record the outcome for the next step's prompt. The diff fields
@@ -1825,6 +1786,8 @@ Right now it's ${temporalState.description}.`;
1825
1786
  error: error instanceof Error ? error.message : String(error),
1826
1787
  context: `Step ${step}: ${parsed.action}`,
1827
1788
  });
1789
+ if (state.cognitiveMode?.system === 1)
1790
+ state.cognitiveMode.system1Errors++;
1828
1791
  lastActionOutcome = {
1829
1792
  action: parsed.action,
1830
1793
  target: parsed.actionTarget,
@@ -1951,9 +1914,7 @@ Answer with JSON:
1951
1914
  // Close browser
1952
1915
  await browser.close();
1953
1916
  // Calculate summary stats
1954
- const avgConfusion = frictionPoints.length > 0
1955
- ? frictionPoints.reduce((sum, _fp) => sum + (state.confusionLevel), 0) / frictionPoints.length
1956
- : state.confusionLevel;
1917
+ const emotion = journeyEmotionSummary(journeyLog, state);
1957
1918
  // Build result
1958
1919
  return {
1959
1920
  ...(options.name ? { name: options.name } : {}),
@@ -1972,8 +1933,8 @@ Answer with JSON:
1972
1933
  fullMonologue,
1973
1934
  finalState: state,
1974
1935
  summary: {
1975
- avgConfusionLevel: avgConfusion,
1976
- maxFrustrationLevel: state.frustrationLevel,
1936
+ avgConfusionLevel: emotion.avgConfusionLevel,
1937
+ maxFrustrationLevel: emotion.maxFrustrationLevel,
1977
1938
  backtrackCount: state.memory.backtrackCount,
1978
1939
  timeInConfusion: frictionPoints.length * 2, // Estimate
1979
1940
  // Decision fatigue metrics (v9.9.0)
@@ -2227,6 +2188,95 @@ STRATEGY:
2227
2188
 
2228
2189
  Respond in JSON format.`;
2229
2190
  }
2191
+ /**
2192
+ * The journey's average confusion and peak frustration, over the state each
2193
+ * step logged plus the final state for the peak. Both read only the final
2194
+ * state before 20.1.3: the "average" added the final confusion once per
2195
+ * friction point and divided by their count, and the "max" was the last
2196
+ * frustration (2026-10-23). With no step logged, both are the final state's.
2197
+ */
2198
+ export function journeyEmotionSummary(steps, final) {
2199
+ if (steps.length === 0)
2200
+ return { avgConfusionLevel: final.confusionLevel, maxFrustrationLevel: final.frustrationLevel };
2201
+ let confusion = 0;
2202
+ let peak = final.frustrationLevel;
2203
+ for (const s of steps) {
2204
+ confusion += s.confusion;
2205
+ if (s.frustration > peak)
2206
+ peak = s.frustration;
2207
+ }
2208
+ return { avgConfusionLevel: confusion / steps.length, maxFrustrationLevel: peak };
2209
+ }
2210
+ /**
2211
+ * The persona a journey runs as.
2212
+ *
2213
+ * A known name resolves to its own record: built-in, custom and account
2214
+ * personas through getPersona, and the accessibility and emotional ones
2215
+ * (cognitive-adhd, anxious-user, ...) through getAnyPersona. Only getPersona
2216
+ * was asked before 20.1.3, so a journey for any of those 15 personas, which is
2217
+ * what empathy_audit starts, ran on traits generated from the name: 14 to 24 of
2218
+ * their 25 traits differed from the persona's own (2026-10-23). A name nothing
2219
+ * knows is still read as a description of the person, as `--persona` says. An
2220
+ * agent persona is refused, because a journey simulates a person.
2221
+ */
2222
+ export function resolveJourneyPersona(name, customTraits) {
2223
+ const known = getPersona(name) ?? getAnyPersona(name);
2224
+ if (known && isAgentPersonaObject(known)) {
2225
+ throw new Error(`"${name}" is an AI agent persona, and a cognitive journey simulates a person. Pick a human persona (cbrowser persona list).`);
2226
+ }
2227
+ const existingPersona = known;
2228
+ let personaObj;
2229
+ if (!existingPersona) {
2230
+ personaObj = createCognitivePersona(name, name, customTraits || {});
2231
+ }
2232
+ else if (customTraits) {
2233
+ // v16.7.1: full default trait set (was only 7, causing trait dropout).
2234
+ // Said 25 until 2026-08-01; the model has 26.
2235
+ const defaultTraits = {
2236
+ // Required traits (7)
2237
+ patience: 0.5,
2238
+ riskTolerance: 0.5,
2239
+ comprehension: 0.5,
2240
+ persistence: 0.5,
2241
+ curiosity: 0.5,
2242
+ workingMemory: 0.5,
2243
+ readingTendency: 0.5,
2244
+ // Optional traits - Tier 1: Core
2245
+ resilience: 0.5,
2246
+ selfEfficacy: 0.5,
2247
+ satisficing: 0.5,
2248
+ trustCalibration: 0.5,
2249
+ interruptRecovery: 0.5,
2250
+ // Optional traits - Tier 2+
2251
+ informationForaging: 0.5,
2252
+ changeBlindness: 0.3,
2253
+ anchoringBias: 0.5,
2254
+ timeHorizon: 0.5,
2255
+ attributionStyle: 0.5,
2256
+ metacognitivePlanning: 0.5,
2257
+ proceduralFluency: 0.5,
2258
+ transferLearning: 0.5,
2259
+ authoritySensitivity: 0.5,
2260
+ emotionalContagion: 0.5,
2261
+ fearOfMissingOut: 0.5,
2262
+ socialProofSensitivity: 0.5,
2263
+ mentalModelFlexibility: 0.5,
2264
+ siteFamiliarity: 0.5,
2265
+ };
2266
+ personaObj = {
2267
+ ...existingPersona,
2268
+ cognitiveTraits: {
2269
+ ...defaultTraits,
2270
+ ...(existingPersona.cognitiveTraits || {}),
2271
+ ...customTraits,
2272
+ },
2273
+ };
2274
+ }
2275
+ else {
2276
+ personaObj = existingPersona;
2277
+ }
2278
+ return personaObj;
2279
+ }
2230
2280
  /**
2231
2281
  * The live per-step decision: one messages.create call, its text blocks read
2232
2282
  * together, and one more ask for the JSON alone when the reply does not hold