wogiflow 1.0.12 → 1.0.13

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.
Files changed (45) hide show
  1. package/.workflow/specs/architecture.md.template +24 -0
  2. package/.workflow/specs/stack.md.template +33 -0
  3. package/.workflow/specs/testing.md.template +36 -0
  4. package/README.md +90 -1
  5. package/package.json +1 -1
  6. package/scripts/MEMORY-ARCHITECTURE.md +150 -0
  7. package/scripts/flow +20 -19
  8. package/scripts/flow-auto-context.js +97 -3
  9. package/scripts/flow-conflict-resolver.js +735 -0
  10. package/scripts/flow-context-gatherer.js +520 -0
  11. package/scripts/flow-context-monitor.js +148 -19
  12. package/scripts/flow-damage-control.js +5 -1
  13. package/scripts/flow-export-profile +168 -1
  14. package/scripts/flow-import-profile +257 -6
  15. package/scripts/flow-instruction-richness.js +182 -18
  16. package/scripts/flow-knowledge-router.js +2 -0
  17. package/scripts/flow-knowledge-sync.js +2 -0
  18. package/scripts/{flow-transcript-chunking.js → flow-long-input-chunking.js} +4 -2
  19. package/scripts/{flow-transcript-parsing.js → flow-long-input-parsing.js} +35 -0
  20. package/scripts/{flow-transcript-stories.js → flow-long-input-stories.js} +86 -38
  21. package/scripts/{flow-transcript-digest.js → flow-long-input.js} +231 -15
  22. package/scripts/flow-memory-db.js +386 -1
  23. package/scripts/flow-memory-sync.js +2 -0
  24. package/scripts/flow-model-adapter.js +53 -29
  25. package/scripts/flow-model-router.js +246 -1
  26. package/scripts/flow-morning.js +94 -0
  27. package/scripts/flow-onboard +223 -10
  28. package/scripts/flow-orchestrate-validation.js +539 -0
  29. package/scripts/flow-orchestrate.js +16 -507
  30. package/scripts/flow-pattern-extractor.js +1265 -0
  31. package/scripts/flow-prompt-composer.js +222 -2
  32. package/scripts/flow-quality-guard.js +594 -0
  33. package/scripts/flow-section-index.js +713 -0
  34. package/scripts/flow-section-resolver.js +484 -0
  35. package/scripts/flow-session-end.js +188 -2
  36. package/scripts/flow-skill-create.js +19 -3
  37. package/scripts/flow-skill-matcher.js +122 -7
  38. package/scripts/flow-statusline-setup.js +218 -0
  39. package/scripts/flow-step-review.js +19 -0
  40. package/scripts/flow-tech-debt.js +734 -0
  41. package/scripts/flow-utils.js +2 -0
  42. package/scripts/hooks/core/long-input-gate.js +293 -0
  43. package/scripts/flow-parallel-detector.js +0 -399
  44. package/scripts/flow-parallel-dispatch.js +0 -987
  45. /package/scripts/{flow-transcript-language.js → flow-long-input-language.js} +0 -0
@@ -0,0 +1,24 @@
1
+ # Architecture
2
+
3
+ ## Pattern
4
+
5
+ <!-- Detected during onboarding -->
6
+ <!-- Examples: MVC, Clean Architecture, DDD, Microservices, Monolith -->
7
+
8
+ ## Structure
9
+
10
+ <!-- Project structure overview -->
11
+ <!-- Key directories and their purposes -->
12
+
13
+ ## Key Decisions
14
+
15
+ <!-- Architecture decisions made for this project -->
16
+ <!-- Trade-offs and rationale -->
17
+
18
+ ## Dependencies
19
+
20
+ <!-- Major dependencies and their purposes -->
21
+
22
+ ---
23
+
24
+ *This file is auto-populated during `flow onboard`. Update manually as architecture evolves.*
@@ -0,0 +1,33 @@
1
+ # Tech Stack
2
+
3
+ ## Framework
4
+
5
+ <!-- Primary framework (e.g., Next.js, NestJS, FastAPI) -->
6
+
7
+ ## Language
8
+
9
+ <!-- Primary language (e.g., TypeScript, Python, Go) -->
10
+
11
+ ## Database
12
+
13
+ <!-- Database system if applicable (e.g., PostgreSQL, MongoDB) -->
14
+
15
+ ## Package Manager
16
+
17
+ <!-- npm, yarn, pnpm, pip, etc. -->
18
+
19
+ ## Build Tools
20
+
21
+ <!-- Build and bundling tools (e.g., Vite, Webpack, esbuild) -->
22
+
23
+ ## Testing
24
+
25
+ <!-- Test frameworks (e.g., Jest, Vitest, pytest) -->
26
+
27
+ ## Other Tools
28
+
29
+ <!-- Linters, formatters, CI/CD tools -->
30
+
31
+ ---
32
+
33
+ *This file is auto-populated during `flow onboard`. Update manually as stack evolves.*
@@ -0,0 +1,36 @@
1
+ # Testing
2
+
3
+ ## Test Framework
4
+
5
+ <!-- Primary test framework (e.g., Jest, Vitest, pytest) -->
6
+
7
+ ## Test Commands
8
+
9
+ ```bash
10
+ # Run all tests
11
+ npm test
12
+
13
+ # Run tests in watch mode
14
+ npm run test:watch
15
+
16
+ # Run specific test file
17
+ npm test -- path/to/test.ts
18
+ ```
19
+
20
+ ## Test Structure
21
+
22
+ <!-- Where tests are located -->
23
+ <!-- Naming conventions -->
24
+
25
+ ## Coverage
26
+
27
+ <!-- Coverage requirements if any -->
28
+ <!-- Coverage commands -->
29
+
30
+ ## E2E Testing
31
+
32
+ <!-- E2E framework if used (e.g., Playwright, Cypress) -->
33
+
34
+ ---
35
+
36
+ *This file is auto-populated during `flow onboard`. Update manually as testing strategy evolves.*
package/README.md CHANGED
@@ -1315,6 +1315,8 @@ When working on files that match a skill's patterns, Claude automatically:
1315
1315
 
1316
1316
  ## Team Backend
1317
1317
 
1318
+ > **Note**: Team Backend infrastructure (Terraform) is defined but Lambda functions are not yet implemented. The local team sync features work, but cloud sync is a placeholder. This is planned for a future release.
1319
+
1318
1320
  AWS-powered backend for team collaboration with shared memory, proposals, and activity tracking.
1319
1321
 
1320
1322
  ### Architecture
@@ -1568,9 +1570,96 @@ flow team status # Show team connection status
1568
1570
  flow team sync # Sync local memory to team
1569
1571
  flow team activity # Show team activity
1570
1572
 
1571
- # Hooksflow setup-hooks install # Install git hooks
1573
+ # Hooks
1574
+ flow setup-hooks install # Install git hooks
1572
1575
  flow setup-hooks --status # Check hook status
1573
1576
  flow setup-hooks --remove # Remove hooks
1577
+
1578
+ # Worktree Isolation
1579
+ flow worktree enable # Enable worktree per task
1580
+ flow worktree disable # Disable worktree isolation
1581
+ flow worktree list # List active worktrees
1582
+ flow worktree cleanup # Remove stale worktrees
1583
+
1584
+ # Task Queue
1585
+ flow queue init <id1> <id2> # Initialize multi-task queue
1586
+ flow queue status # Show queue status
1587
+ flow queue advance # Move to next task
1588
+ flow queue clear # Clear the queue
1589
+
1590
+ # Suspend/Resume (Durable Sessions)
1591
+ flow suspend # Suspend current task
1592
+ flow suspend --wait-ci # Wait for CI/CD
1593
+ flow suspend --review # Wait for human review
1594
+ flow resume # Resume suspended task
1595
+ flow resume --approve # Approve and resume
1596
+ flow session status # Show session status
1597
+
1598
+ # Issue Tracker Integration
1599
+ flow jira list # List assigned Jira issues
1600
+ flow jira sync # Import issues to ready.json
1601
+ flow jira push # Push completed tasks
1602
+ flow linear list # List assigned Linear issues
1603
+ flow linear sync # Import issues to ready.json
1604
+ flow external-tasks # List from all integrations
1605
+
1606
+ # Background Sync
1607
+ flow sync-daemon start # Start background sync
1608
+ flow sync-daemon stop # Stop daemon
1609
+ flow sync-daemon status # Show daemon status
1610
+
1611
+ # Intelligent Routing
1612
+ flow route "<task>" # Get routing recommendation
1613
+ flow route --strategy <s> # Use specific strategy
1614
+
1615
+ # Multi-Approach Sessions
1616
+ flow multi-approach # Start multi-approach session
1617
+ flow multi-approach --analyze # Analyze without starting
1618
+
1619
+ # Metrics & Analysis
1620
+ flow metrics # Show command statistics
1621
+ flow metrics --problems # Show only failures
1622
+ flow metrics --reset # Clear all metrics
1623
+
1624
+ # Cascade Fallback
1625
+ flow cascade status # Show cascade state
1626
+ flow cascade reset # Reset failure tracking
1627
+ flow cascade config # Show configuration
1628
+
1629
+ # Memory Management
1630
+ flow entropy # Show memory entropy
1631
+ flow entropy --auto # Auto-compact if high
1632
+ flow memory-sync # Check pattern promotion
1633
+ flow memory-sync --auto # Auto-promote patterns
1634
+ flow compact-memory # Run full compaction
1635
+
1636
+ # PRD Management
1637
+ flow prd load <file> # Load PRD into memory
1638
+ flow prd context <task> # Get PRD context for task
1639
+ flow prd list # List loaded PRDs
1640
+ flow prd clear # Clear PRD data
1641
+
1642
+ # Release Channels
1643
+ flow channel show # Show current channel
1644
+ flow channel set <name> # Set channel (stable/beta/canary)
1645
+ flow channel list # List available channels
1646
+
1647
+ # Complexity & Context
1648
+ flow complexity "<task>" # Assess task complexity
1649
+ flow context-init "<task>" # Initialize context for task
1650
+ flow auto-context "<task>" # Preview auto-loaded context
1651
+
1652
+ # Models
1653
+ flow models list # List registered models
1654
+ flow models info <model> # Show model details
1655
+ flow models route <type> # Get routing recommendation
1656
+ flow models stats # Show performance stats
1657
+ flow model-adapter # Show adapter info
1658
+ flow model-adapter --stats # Show per-model statistics
1659
+
1660
+ # Learning System
1661
+ flow learning tiers # Show patterns by confidence
1662
+ flow learning stats # Show learning statistics
1574
1663
  ```
1575
1664
 
1576
1665
  ---
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wogiflow",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "description": "AI-powered development workflow management system with multi-model support",
5
5
  "main": "lib/index.js",
6
6
  "bin": {
@@ -0,0 +1,150 @@
1
+ # Memory & Knowledge System Architecture
2
+
3
+ This document clarifies the boundaries between the memory and knowledge modules.
4
+
5
+ ## Overview
6
+
7
+ ```
8
+ ┌─────────────────────────────────────────────────────────────────┐
9
+ │ KNOWLEDGE LAYER │
10
+ │ Where learnings/rules are stored and retrieved │
11
+ ├─────────────────────────────────────────────────────────────────┤
12
+ │ │
13
+ │ ┌─────────────────────┐ ┌─────────────────────┐ │
14
+ │ │ flow-knowledge- │ │ flow-knowledge- │ │
15
+ │ │ router.js │ │ sync.js │ │
16
+ │ │ │ │ │ │
17
+ │ │ WHERE to store │ │ FRESHNESS of │ │
18
+ │ │ learnings │ │ knowledge files │ │
19
+ │ │ │ │ │ │
20
+ │ │ Routes to: │ │ Tracks: │ │
21
+ │ │ - model-specific │ │ - stack.md │ │
22
+ │ │ - skill │ │ - architecture.md │ │
23
+ │ │ - project │ │ - testing.md │ │
24
+ │ │ - team │ │ │ │
25
+ │ └─────────────────────┘ └─────────────────────┘ │
26
+ │ │
27
+ └─────────────────────────────────────────────────────────────────┘
28
+
29
+ ┌─────────────────────────────────────────────────────────────────┐
30
+ │ MEMORY LAYER │
31
+ │ Persistent fact storage and retrieval │
32
+ ├─────────────────────────────────────────────────────────────────┤
33
+ │ │
34
+ │ ┌─────────────────────┐ ┌─────────────────────┐ │
35
+ │ │ flow-memory-db.js │ │ flow-memory-sync.js │ │
36
+ │ │ │ │ │ │
37
+ │ │ DATABASE operations │ │ PROMOTION of │ │
38
+ │ │ │ │ facts to rules │ │
39
+ │ │ - SQLite + sql.js │ │ │ │
40
+ │ │ - Embeddings │ │ Promotes: │ │
41
+ │ │ - Semantic search │ │ high-relevance │ │
42
+ │ │ - Facts/Proposals │ │ facts → decisions.md│ │
43
+ │ │ - PRD storage │ │ │ │
44
+ │ └──────────┬──────────┘ └──────────┬──────────┘ │
45
+ │ │ │ │
46
+ │ └───────────────────────────┘ │
47
+ │ │ │
48
+ │ ▼ │
49
+ │ ┌─────────────────────┐ │
50
+ │ │ .workflow/memory/ │ │
51
+ │ │ local.db │ │
52
+ │ └─────────────────────┘ │
53
+ │ │
54
+ └─────────────────────────────────────────────────────────────────┘
55
+ ```
56
+
57
+ ## Module Responsibilities
58
+
59
+ ### flow-knowledge-router.js
60
+ **Purpose**: Determine WHERE learnings should be stored.
61
+
62
+ **Input**: A correction/learning text + context
63
+ **Output**: Routing recommendation (model-specific, skill, project, or team)
64
+
65
+ **Commands**:
66
+ ```bash
67
+ flow knowledge-route detect "<text>" # Detect route
68
+ flow knowledge-route store "<text>" # Store with detected route
69
+ flow knowledge-route routes # Show all routes
70
+ ```
71
+
72
+ ### flow-knowledge-sync.js
73
+ **Purpose**: Track FRESHNESS of knowledge files.
74
+
75
+ **Monitors**:
76
+ - package.json → stack.md
77
+ - src/ structure → architecture.md
78
+ - test config → testing.md
79
+
80
+ **Commands**:
81
+ ```bash
82
+ flow knowledge-sync status # Check sync status
83
+ flow knowledge-sync regenerate # Regenerate stale files
84
+ ```
85
+
86
+ ### flow-memory-db.js
87
+ **Purpose**: DATABASE operations for persistent memory.
88
+
89
+ **Features**:
90
+ - SQLite database using sql.js (pure JS)
91
+ - Embedding generation via @xenova/transformers
92
+ - Semantic similarity search
93
+ - Facts, proposals, and PRD chunk storage
94
+
95
+ **Used by**: MCP memory server, memory-sync
96
+
97
+ ### flow-memory-sync.js
98
+ **Purpose**: PROMOTE high-relevance facts to decisions.md.
99
+
100
+ **Flow**:
101
+ 1. Scan memory DB for high-relevance facts
102
+ 2. Check if fact applies broadly (not one-off)
103
+ 3. Propose promotion to decisions.md
104
+ 4. On approval, add to decisions.md
105
+
106
+ **Commands**:
107
+ ```bash
108
+ flow memory-sync # Check for promotable patterns
109
+ flow memory-sync --auto # Auto-promote without asking
110
+ flow memory-sync --list # List candidates only
111
+ ```
112
+
113
+ ## Data Flow
114
+
115
+ ```
116
+ User correction
117
+
118
+
119
+ ┌─────────────────────┐
120
+ │ knowledge-router │──────► Route to storage location
121
+ └─────────────────────┘
122
+
123
+
124
+ ┌─────────────────────┐
125
+ │ memory-db │──────► Store in SQLite
126
+ └─────────────────────┘
127
+
128
+
129
+ ┌─────────────────────┐
130
+ │ memory-sync │──────► Promote to decisions.md
131
+ └─────────────────────┘
132
+
133
+
134
+ ┌─────────────────────┐
135
+ │ knowledge-sync │──────► Regenerate knowledge files
136
+ └─────────────────────┘
137
+ ```
138
+
139
+ ## Why Separate Modules?
140
+
141
+ 1. **Single Responsibility**: Each module does one thing well
142
+ 2. **Testability**: Easier to test in isolation
143
+ 3. **Composability**: Can be used independently or together
144
+ 4. **Maintainability**: Changes to one don't affect others
145
+
146
+ ## Future Considerations
147
+
148
+ - Consider extracting common utilities to `flow-memory-utils.js`
149
+ - May add `flow-knowledge-index.js` for knowledge search
150
+ - Could add `flow-memory-export.js` for team sharing
package/scripts/flow CHANGED
@@ -76,6 +76,7 @@ show_help() {
76
76
  echo " hooks setup Install CLI hooks (Claude Code, etc.)"
77
77
  echo " hooks remove Remove CLI hooks"
78
78
  echo " hooks status Show CLI hooks status"
79
+ echo " statusline-setup Configure Claude Code status line"
79
80
  echo " archive Archive old request-log entries"
80
81
  echo " watch Run file watcher for auto-validation"
81
82
  echo ""
@@ -172,8 +173,6 @@ show_help() {
172
173
  echo "Parallel Execution:"
173
174
  echo " parallel config Show parallel execution config"
174
175
  echo " parallel check Check tasks for parallel potential"
175
- echo " parallel analyze Analyze tasks for parallel potential"
176
- echo " parallel suggest Check if parallel should be suggested"
177
176
  echo " parallel enable Enable parallel execution"
178
177
  echo " parallel disable Disable parallel execution"
179
178
  echo ""
@@ -277,9 +276,6 @@ show_help() {
277
276
  echo " context-init \"task\" Initialize context for a task"
278
277
  echo ""
279
278
  echo "Advanced Execution (Phase 4):"
280
- echo " dispatch analyze \"<task>\" Analyze task for parallel execution"
281
- echo " dispatch plan \"<task>\" Create dispatch plan"
282
- echo " dispatch status Show dispatch status"
283
279
  echo " ctx-score score --task Score context items by relevance"
284
280
  echo " ctx-score budget --tokens Fit context within token budget"
285
281
  echo " ctx-score analyze --file Analyze file for context inclusion"
@@ -287,6 +283,13 @@ show_help() {
287
283
  echo " confidence check --file Check confidence of file"
288
284
  echo " confidence stats Show confidence statistics"
289
285
  echo ""
286
+ echo "Input & Editing:"
287
+ echo " voice-input Voice-to-transcript input"
288
+ echo " voice-input setup Install/configure voice dependencies"
289
+ echo " voice-input record Record and transcribe audio"
290
+ echo " guided-edit \"task\" Step-by-step guided multi-file editing"
291
+ echo " guided-edit status Show current guided edit session"
292
+ echo ""
290
293
  echo "Memory & Knowledge (v1.8):"
291
294
  echo " memory search <query> Search stored facts"
292
295
  echo " memory stats Show memory statistics"
@@ -401,6 +404,9 @@ case "${1:-}" in
401
404
  hooks)
402
405
  node "$SCRIPT_DIR/flow-hooks.js" "${@:2}"
403
406
  ;;
407
+ statusline-setup|statusline)
408
+ node "$SCRIPT_DIR/flow-statusline-setup.js" "${@:2}"
409
+ ;;
404
410
  update-map)
405
411
  "$SCRIPT_DIR/flow-update-map" "${@:2}"
406
412
  ;;
@@ -460,12 +466,6 @@ case "${1:-}" in
460
466
  check)
461
467
  node "$SCRIPT_DIR/flow-parallel.js" check
462
468
  ;;
463
- analyze)
464
- node "$SCRIPT_DIR/flow-parallel-detector.js" analyze
465
- ;;
466
- suggest)
467
- node "$SCRIPT_DIR/flow-parallel-detector.js" suggest
468
- ;;
469
469
  enable)
470
470
  node "$SCRIPT_DIR/flow-config-set.js" parallel.enabled true
471
471
  ;;
@@ -476,7 +476,7 @@ case "${1:-}" in
476
476
  node "$SCRIPT_DIR/flow-config-set.js" parallel.autoApprove true
477
477
  ;;
478
478
  *)
479
- echo "Usage: flow parallel [config|check|analyze|suggest|enable|disable|auto-approve]"
479
+ echo "Usage: flow parallel [config|check|enable|disable|auto-approve]"
480
480
  ;;
481
481
  esac
482
482
  ;;
@@ -798,10 +798,6 @@ case "${1:-}" in
798
798
  # Phase 3: Tiered learning system
799
799
  node "$SCRIPT_DIR/flow-tiered-learning.js" "${@:2}"
800
800
  ;;
801
- dispatch)
802
- # Phase 4: Parallel dispatch system
803
- node "$SCRIPT_DIR/flow-parallel-dispatch.js" "${@:2}"
804
- ;;
805
801
  ctx-score)
806
802
  # Phase 4: Context priority scoring
807
803
  node "$SCRIPT_DIR/flow-context-scoring.js" "${@:2}"
@@ -941,8 +937,12 @@ case "${1:-}" in
941
937
  voice-input|voice)
942
938
  node "$SCRIPT_DIR/flow-voice-input.js" "${@:2}"
943
939
  ;;
944
- transcript-digest|digest)
945
- node "$SCRIPT_DIR/flow-transcript-digest.js" "${@:2}"
940
+ guided-edit)
941
+ node "$SCRIPT_DIR/flow-guided-edit.js" "${@:2}"
942
+ ;;
943
+ long-input|long-input-process|transcript-digest|digest)
944
+ # long-input is the new name, transcript-digest kept for backward compatibility
945
+ node "$SCRIPT_DIR/flow-long-input.js" "${@:2}"
946
946
  ;;
947
947
  version|--version|-v)
948
948
  show_version
@@ -970,7 +970,8 @@ case "${1:-}" in
970
970
  parallel) echo "Manage parallel execution. Subcommands: config, check, enable, disable" ;;
971
971
  worktree) echo "Manage worktree isolation. Subcommands: enable, disable, list, cleanup" ;;
972
972
  voice-input|voice) echo "Voice-to-transcript input. Subcommands: setup, status, test, record" ;;
973
- transcript-digest|digest) echo "Transcript digestion. Subcommands: status, new, check, topics, save-topics" ;;
973
+ long-input|long-input-process|transcript-digest|digest) echo "Long input processing. Ensures nothing missed from long prompts/transcripts/specs. Subcommands: status, new, check, topics, save-topics" ;;
974
+ guided-edit) echo "Step-by-step guided multi-file editing. Usage: flow guided-edit \"task description\"" ;;
974
975
  *) echo "No detailed help for '$2'. Run 'flow help' for all commands." ;;
975
976
  esac
976
977
  ;;
@@ -33,7 +33,8 @@ const {
33
33
  findReactComponents,
34
34
  findCustomHooks,
35
35
  findTypeDefinitions,
36
- isPathWithinProject
36
+ isPathWithinProject,
37
+ safeJsonParse
37
38
  } = require('./flow-utils');
38
39
 
39
40
  // Semantic memory search (optional - may not be initialized)
@@ -45,6 +46,14 @@ try {
45
46
  // Memory DB not available - that's ok
46
47
  }
47
48
 
49
+ // Smart Context System (Phase 2) - optional
50
+ let smartContextGatherer = null;
51
+ try {
52
+ smartContextGatherer = require('./flow-context-gatherer');
53
+ } catch {
54
+ // Smart context gatherer not available - that's ok
55
+ }
56
+
48
57
  const PROJECT_ROOT = getProjectRoot();
49
58
 
50
59
  // ============================================================
@@ -350,7 +359,9 @@ function searchComponentIndex(keywords, config = null) {
350
359
  const maxComponentMatches = cfg.autoContext?.maxComponentMatches || 15;
351
360
 
352
361
  try {
353
- const index = JSON.parse(fs.readFileSync(indexPath, 'utf-8'));
362
+ // Use safeJsonParse for prototype pollution protection
363
+ const index = safeJsonParse(indexPath, null);
364
+ if (!index) return results;
354
365
  const components = index.components || [];
355
366
 
356
367
  const allKeywords = [...keywords.high, ...keywords.medium];
@@ -497,7 +508,9 @@ function searchRelatedTasks(keywords) {
497
508
  if (!fs.existsSync(PATHS.ready)) return results;
498
509
 
499
510
  try {
500
- const data = JSON.parse(fs.readFileSync(PATHS.ready, 'utf-8'));
511
+ // Use safeJsonParse for prototype pollution protection
512
+ const data = safeJsonParse(PATHS.ready, null);
513
+ if (!data) return results;
501
514
  const allTasks = [
502
515
  ...(data.ready || []),
503
516
  ...(data.inProgress || []),
@@ -783,6 +796,50 @@ function searchWithAstGrep(keywords, taskType = null, config = null) {
783
796
  return results;
784
797
  }
785
798
 
799
+ // ============================================================
800
+ // Smart Context (Phase 2)
801
+ // ============================================================
802
+
803
+ /**
804
+ * Get smart context using section-level references
805
+ * This is the new dynamic context system that replaces hardcoded limits
806
+ * @param {string} description - Task description
807
+ * @param {object} options - { model, maxTokens }
808
+ * @returns {object} - Smart context result
809
+ */
810
+ async function getSmartContext(description, options = {}) {
811
+ if (!smartContextGatherer) {
812
+ return null; // Fall back to legacy behavior
813
+ }
814
+
815
+ const config = getConfig();
816
+ const model = options.model || config.multiModel?.orchestrator?.model || 'claude-sonnet-4';
817
+
818
+ try {
819
+ const result = await smartContextGatherer.gatherContext({
820
+ task: description,
821
+ model,
822
+ maxTokens: options.maxTokens,
823
+ format: 'full'
824
+ });
825
+
826
+ return {
827
+ enabled: true,
828
+ strategy: 'dynamic',
829
+ sectionContext: result.context,
830
+ sections: result.sections,
831
+ stats: result.stats,
832
+ message: `Smart context: ${result.stats.sectionsIncluded} sections, ${result.stats.totalTokens} tokens (${result.stats.budgetUsed})`
833
+ };
834
+ } catch (err) {
835
+ // Fall back to legacy behavior on error
836
+ if (config.debug) {
837
+ console.warn(`Smart context failed: ${err.message}`);
838
+ }
839
+ return null;
840
+ }
841
+ }
842
+
786
843
  // ============================================================
787
844
  // Main Context Loading
788
845
  // ============================================================
@@ -791,6 +848,8 @@ function searchWithAstGrep(keywords, taskType = null, config = null) {
791
848
  * Get auto-context for a task description
792
849
  * Returns prioritized list of relevant files and context
793
850
  * Now async to support semantic memory search
851
+ *
852
+ * v3.0: Supports 'dynamic' strategy using Smart Context System
794
853
  */
795
854
  async function getAutoContext(description, options = {}) {
796
855
  const config = getConfig();
@@ -800,6 +859,39 @@ async function getAutoContext(description, options = {}) {
800
859
  return { enabled: false, files: [], context: [] };
801
860
  }
802
861
 
862
+ // v3.0: Use Smart Context System if strategy is 'dynamic'
863
+ const strategy = config.autoContext?.strategy || 'fixed';
864
+ if (strategy === 'dynamic' && smartContextGatherer) {
865
+ const smartResult = await getSmartContext(description, options);
866
+ if (smartResult) {
867
+ // Merge smart context with legacy context for backward compatibility
868
+ // The smart context provides section-level rules, legacy provides file context
869
+ const legacyResult = await getLegacyContext(description, options, config);
870
+
871
+ return {
872
+ ...legacyResult,
873
+ strategy: 'dynamic',
874
+ sectionContext: smartResult.sectionContext,
875
+ sections: smartResult.sections,
876
+ smartStats: smartResult.stats,
877
+ message: smartResult.message + (legacyResult.files.length > 0
878
+ ? ` | ${legacyResult.files.length} files`
879
+ : '')
880
+ };
881
+ }
882
+ }
883
+
884
+ // Fall back to legacy (fixed) strategy
885
+ return await getLegacyContext(description, options, config);
886
+ }
887
+
888
+ /**
889
+ * Legacy context loading (fixed strategy)
890
+ * This is the original implementation with hardcoded limits
891
+ */
892
+ async function getLegacyContext(description, options = {}, config = null) {
893
+ config = config || getConfig();
894
+
803
895
  // v2.0: Check and refresh stale component index
804
896
  if (config.componentIndex?.autoScan !== false) {
805
897
  checkAndRefreshIndex(config);
@@ -1093,6 +1185,8 @@ module.exports = {
1093
1185
  inferTaskType,
1094
1186
  checkAndRefreshIndex,
1095
1187
  getAutoContext,
1188
+ getLegacyContext, // v3.0: Legacy context loading
1189
+ getSmartContext, // v3.0: Smart context with section-level refs
1096
1190
  formatAutoContext
1097
1191
  };
1098
1192