bingocode 1.1.184 → 1.1.185

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bingocode",
3
- "version": "1.1.184",
3
+ "version": "1.1.185",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "claude": "bin/claude-win.cjs",
@@ -135,16 +135,7 @@ type State = {
135
135
  // (useScheduledTasks). Set by cronScheduler.start() when the JSON has
136
136
  // entries, or by CronCreateTool. Not persisted.
137
137
  scheduledTasksEnabled: boolean
138
- // Session-only goal condition for /goal command. Null when no active goal.
139
- goalCondition: string | null
140
- goalIterationCount: number
141
- goalMaxIterations: number
142
- // Goal evaluator history for detecting repeated gaps
143
- goalEvalHistory: {
144
- lastGap: string | null
145
- consecutiveSameGapCount: number
146
- }
147
- // Session-only cron tasks created via CronCreate with durable: false.
138
+ // Session-only cron tasks created via CronCreate with durable: false.
148
139
  // Fire on schedule like file-backed tasks but are never written to
149
140
  // .claude/scheduled_tasks.json — they die with the process. Typed via
150
141
  // SessionCronTask below (not importing from cronTasks.ts keeps
@@ -366,15 +357,7 @@ function getInitialState(): State {
366
357
  sessionBypassPermissionsMode: false,
367
358
  // Scheduled tasks disabled until flag or dialog enables them
368
359
  scheduledTasksEnabled: false,
369
- // Goal condition for /goal command (null = no active goal)
370
- goalCondition: null,
371
- goalIterationCount: 0,
372
- goalMaxIterations: 20,
373
- goalEvalHistory: {
374
- lastGap: null,
375
- consecutiveSameGapCount: 0,
376
- },
377
- sessionCronTasks: [],
360
+ sessionCronTasks: [],
378
361
  sessionCreatedTeams: new Set(),
379
362
  // Session-only trust flag (not persisted to disk)
380
363
  sessionTrustAccepted: false,
@@ -1794,85 +1777,4 @@ export function setPromptId(id: string | null): void {
1794
1777
  // ============================================================================
1795
1778
 
1796
1779
  // ============================================================================
1797
- // /goal session state accessors (DEPRECATED — use goalStore.ts instead)
1798
- // ============================================================================
1799
- // These accessors are kept for backwards compatibility with existing code.
1800
- // They delegate to the new GoalStore in src/utils/goalStore.ts.
1801
- // New code should import from goalStore.ts directly.
1802
- // TODO: remove after all consumers are migrated.
1803
-
1804
- import { getGoalState as _getGoalState } from '../utils/goalStore.js'
1805
-
1806
- export function getGoalCondition(): string | null {
1807
- try {
1808
- return _getGoalState().userGoal?.text ?? _getGoalState().operationalGoal?.text ?? null
1809
- } catch {
1810
- return STATE.goalCondition // fallback to old field during migration
1811
- }
1812
- }
1813
-
1814
- export function setGoalCondition(condition: string | null): void {
1815
- if (condition) {
1816
- try {
1817
- // Delegate to new store for structured goal management
1818
- const { setUserGoal: _setUserGoal, setOperationalGoal: _setOperationalGoal } = require('../utils/goalStore.js')
1819
- _setUserGoal(condition)
1820
- _setOperationalGoal(condition)
1821
- } catch {
1822
- STATE.goalCondition = condition // fallback
1823
- STATE.goalIterationCount = 0
1824
- }
1825
- } else {
1826
- STATE.goalCondition = null
1827
- STATE.goalIterationCount = 0
1828
- }
1829
- }
1830
-
1831
- export function getGoalIterationCount(): number {
1832
- try {
1833
- return _getGoalState().metrics.iterationCount
1834
- } catch {
1835
- return STATE.goalIterationCount
1836
- }
1837
- }
1838
-
1839
- export function incrementGoalIterationCount(): void {
1840
- try {
1841
- const { incrementIteration } = require('../utils/goalStore.js')
1842
- incrementIteration()
1843
- } catch {
1844
- STATE.goalIterationCount++
1845
- }
1846
- }
1847
-
1848
- export function getGoalMaxIterations(): number {
1849
- try {
1850
- return _getGoalState().metrics.maxIterations
1851
- } catch {
1852
- return STATE.goalMaxIterations
1853
- }
1854
- }
1855
-
1856
- // Goal evaluator history accessors (DEPRECATED — use goalStore.ts)
1857
- export function getGoalEvalHistory() {
1858
- try {
1859
- return _getGoalState().metrics.evalHistory
1860
- } catch {
1861
- return STATE.goalEvalHistory
1862
- }
1863
- }
1864
-
1865
- export function updateGoalEvalHistory(lastGap: string | null): void {
1866
- try {
1867
- const { recordEvalGap: _recordEvalGap } = require('../utils/goalStore.js')
1868
- _recordEvalGap(lastGap)
1869
- } catch {
1870
- if (lastGap === STATE.goalEvalHistory.lastGap) {
1871
- STATE.goalEvalHistory.consecutiveSameGapCount++
1872
- } else {
1873
- STATE.goalEvalHistory.lastGap = lastGap
1874
- STATE.goalEvalHistory.consecutiveSameGapCount = 1
1875
- }
1876
- }
1877
- }
1878
1780
 
@@ -3,21 +3,23 @@
3
3
  *
4
4
  * Fires after each turn completes (triggered by lastQueryCompletionTime change).
5
5
  * Evaluates progress toward active goal using env-aware evaluator v2.
6
+ *
7
+ * Migrated from old state.ts flat fields to the new GoalStore API.
8
+ * All state access goes through GoalStore — no more STATE.goalCondition fallbacks.
6
9
  */
7
10
 
8
11
  import { useEffect, useRef } from 'react'
9
12
  import type { MutableRefObject } from 'react'
10
13
  import type { MessageType } from '../components/messages.js'
11
14
  import {
12
- getGoalCondition,
13
- getGoalIterationCount,
14
- getGoalMaxIterations,
15
- incrementGoalIterationCount,
16
- setGoalCondition,
17
- getGoalEvalHistory,
18
- updateGoalEvalHistory,
19
- } from '../bootstrap/state.js'
20
- import { getGoalState, recalculateProgress } from '../utils/goalStore.js'
15
+ getGoalState,
16
+ recalculateProgress,
17
+ incrementIteration,
18
+ recordEvalGap,
19
+ getActiveGoalId,
20
+ getReadySubGoals,
21
+ getBlockedSubGoals,
22
+ } from '../utils/goalStore.js'
21
23
  import { enqueue } from '../utils/messageQueueManager.js'
22
24
  import { evaluateGoal } from '../utils/goalEvaluator.js'
23
25
 
@@ -47,7 +49,8 @@ export function useGoalEvaluator({
47
49
  const evaluating = useRef(false)
48
50
 
49
51
  useEffect(() => {
50
- const condition = getGoalCondition()
52
+ const goalState = getGoalState()
53
+ const condition = goalState.userGoal?.text ?? null
51
54
  if (!condition) return
52
55
  if (isQueryActive) return
53
56
  if (lastQueryCompletionTime === 0) return
@@ -59,56 +62,71 @@ export function useGoalEvaluator({
59
62
 
60
63
  void (async () => {
61
64
  try {
62
- const iterCount = getGoalIterationCount()
63
- const maxIter = getGoalMaxIterations()
65
+ const iterCount = goalState.metrics.iterationCount
66
+ const maxIter = goalState.metrics.maxIterations
64
67
 
65
- // Max iterations check
68
+ // Max iterations check — circuit breaker
66
69
  if (iterCount >= maxIter) {
67
- setGoalCondition(null)
70
+ // Clear goal from store (delegates to clear() which resets engine too)
71
+ const { clear } = require('../utils/goalStore.js')
72
+ clear()
68
73
  enqueue({
69
- value: `⚠️ /goal stopped after ${maxIter} iterations. Goal not achieved: "${condition}"`,
74
+ value: `Goal not achieved after ${maxIter} iterations. Goal was: "${condition}"`,
70
75
  mode: 'task-notification',
71
76
  priority: 'now',
72
77
  })
73
78
  return
74
79
  }
75
80
 
76
- // Get current goal state + sub-goal from store
81
+ // Get messages + current sub-goal for evaluation context
77
82
  const messages = messagesRef.current
78
- const goalState = getGoalState()
79
83
  const currentSubGoal = goalState.immediateGoal
80
84
  ? goalState.dag.nodes.get(goalState.immediateGoal.subGoalId)
81
85
  : undefined
82
86
 
83
- // Run environment-aware evaluation
87
+ // Run environment-aware evaluation (rule engine + semantic + final)
84
88
  const result = await evaluateGoal(condition, messages, currentSubGoal)
85
89
 
86
- // Race: user may have cleared goal during await
87
- if (getGoalCondition() !== condition) return
90
+ // Race: user may have cleared goal during async evaluation
91
+ if (!getActiveGoalId()) return
88
92
 
89
- incrementGoalIterationCount()
90
- updateGoalEvalHistory(result.gap)
93
+ incrementIteration()
94
+ recordEvalGap(result.gap)
91
95
  recalculateProgress()
92
96
 
97
+ // Check active sub-goals and blocked count for drift diagnosis
98
+ const ready = getReadySubGoals()
99
+ const blocked = getBlockedSubGoals()
100
+ if (blocked.length > 0 && ready.length === 0) {
101
+ // All sub-goals blocked — need to replan or escalate
102
+ void ready
103
+ void blocked
104
+ }
105
+
93
106
  // Circuit breaker: 3 consecutive same gap
94
- const evalHistory = getGoalEvalHistory()
107
+ const evalHistory = goalState.metrics.evalHistory
95
108
  const isRepeatedGap = evalHistory.consecutiveSameGapCount >= 3 && result.gap !== null
96
109
 
97
110
  if (result.satisfied) {
98
- setGoalCondition(null)
111
+ // Goal achieved — clear from store and file system
112
+ const { clearAndDelete } = require('../utils/goalStore.js')
113
+ clearAndDelete()
99
114
  enqueue({
100
- value: `✅ Goal achieved (iteration ${iterCount + 1}): ${result.reason}`,
115
+ value: `Goal achieved (iteration ${iterCount + 1}): ${result.reason}`,
101
116
  mode: 'task-notification',
102
117
  priority: 'now',
103
118
  })
104
119
  } else if (isRepeatedGap) {
105
- setGoalCondition(null)
120
+ // Circuit breaker — same gap repeated 3 times, stop looping
121
+ const { clear } = require('../utils/goalStore.js')
122
+ clear()
106
123
  enqueue({
107
- value: `⚠️ Goal evaluator stopped — same gap "${result.gap}" 3x. Adjust approach or output EVAL blocks.`,
124
+ value: `Goal evaluator stopped — same gap "${result.gap}" ${evalHistory.consecutiveSameGapCount}x. Adjust approach or output EVAL blocks.`,
108
125
  mode: 'task-notification',
109
126
  priority: 'now',
110
127
  })
111
128
  } else {
129
+ // Not yet satisfied — continue
112
130
  const continueMsg = result.gap
113
131
  ? `Goal not yet met (${iterCount + 1}/${maxIter}). Gap: ${result.gap}. Continue toward: "${condition}"`
114
132
  : `Goal not yet met (${iterCount + 1}/${maxIter}, reason: ${result.reason}). Continue toward: "${condition}"`
@@ -118,9 +136,12 @@ export function useGoalEvaluator({
118
136
  priority: 'now',
119
137
  })
120
138
  }
139
+ } catch (err) {
140
+ // Evaluation error is non-fatal — log and continue
141
+ console.error('[GoalEvaluator] Evaluation error:', err)
121
142
  } finally {
122
143
  evaluating.current = false
123
144
  }
124
145
  })()
125
- }, [lastQueryCompletionTime, isQueryActive])
146
+ }, [lastQueryCompletionTime, isQueryActive]) // messagesRef is stable ref — not included as dep
126
147
  }