gencode-ai 0.3.0 → 0.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/RELEASE_NOTES_v0.4.0.md +140 -0
- package/dist/agent/agent.d.ts +17 -2
- package/dist/agent/agent.d.ts.map +1 -1
- package/dist/agent/agent.js +279 -49
- package/dist/agent/agent.js.map +1 -1
- package/dist/agent/types.d.ts +15 -1
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/checkpointing/checkpoint-manager.d.ts +24 -0
- package/dist/checkpointing/checkpoint-manager.d.ts.map +1 -1
- package/dist/checkpointing/checkpoint-manager.js +28 -0
- package/dist/checkpointing/checkpoint-manager.js.map +1 -1
- package/dist/cli/components/App.d.ts +8 -0
- package/dist/cli/components/App.d.ts.map +1 -1
- package/dist/cli/components/App.js +478 -36
- package/dist/cli/components/App.js.map +1 -1
- package/dist/cli/components/CommandSuggestions.d.ts.map +1 -1
- package/dist/cli/components/CommandSuggestions.js +2 -0
- package/dist/cli/components/CommandSuggestions.js.map +1 -1
- package/dist/cli/components/Header.d.ts +6 -1
- package/dist/cli/components/Header.d.ts.map +1 -1
- package/dist/cli/components/Header.js +3 -3
- package/dist/cli/components/Header.js.map +1 -1
- package/dist/cli/components/Messages.d.ts.map +1 -1
- package/dist/cli/components/Messages.js +7 -9
- package/dist/cli/components/Messages.js.map +1 -1
- package/dist/cli/index.js +3 -2
- package/dist/cli/index.js.map +1 -1
- package/dist/config/types.d.ts +20 -1
- package/dist/config/types.d.ts.map +1 -1
- package/dist/config/types.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/input/history-manager.d.ts +78 -0
- package/dist/input/history-manager.d.ts.map +1 -0
- package/dist/input/history-manager.js +224 -0
- package/dist/input/history-manager.js.map +1 -0
- package/dist/input/index.d.ts +6 -0
- package/dist/input/index.d.ts.map +1 -0
- package/dist/input/index.js +5 -0
- package/dist/input/index.js.map +1 -0
- package/dist/prompts/index.js +3 -3
- package/dist/prompts/index.js.map +1 -1
- package/dist/providers/gemini.d.ts.map +1 -1
- package/dist/providers/gemini.js +33 -2
- package/dist/providers/gemini.js.map +1 -1
- package/dist/providers/google.d.ts +22 -0
- package/dist/providers/google.d.ts.map +1 -0
- package/dist/providers/google.js +297 -0
- package/dist/providers/google.js.map +1 -0
- package/dist/providers/index.d.ts +4 -4
- package/dist/providers/index.js +11 -11
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/openai.d.ts.map +1 -1
- package/dist/providers/openai.js +6 -0
- package/dist/providers/openai.js.map +1 -1
- package/dist/providers/registry.js +3 -3
- package/dist/providers/registry.js.map +1 -1
- package/dist/providers/types.d.ts +30 -4
- package/dist/providers/types.d.ts.map +1 -1
- package/dist/session/compression/engine.d.ts +109 -0
- package/dist/session/compression/engine.d.ts.map +1 -0
- package/dist/session/compression/engine.js +311 -0
- package/dist/session/compression/engine.js.map +1 -0
- package/dist/session/compression/index.d.ts +12 -0
- package/dist/session/compression/index.d.ts.map +1 -0
- package/dist/session/compression/index.js +11 -0
- package/dist/session/compression/index.js.map +1 -0
- package/dist/session/compression/types.d.ts +90 -0
- package/dist/session/compression/types.d.ts.map +1 -0
- package/dist/session/compression/types.js +17 -0
- package/dist/session/compression/types.js.map +1 -0
- package/dist/session/manager.d.ts +64 -3
- package/dist/session/manager.d.ts.map +1 -1
- package/dist/session/manager.js +254 -2
- package/dist/session/manager.js.map +1 -1
- package/dist/session/types.d.ts +16 -0
- package/dist/session/types.d.ts.map +1 -1
- package/dist/session/types.js.map +1 -1
- package/docs/README.md +1 -0
- package/docs/diagrams/compression-decision.mmd +30 -0
- package/docs/diagrams/compression-workflow.mmd +54 -0
- package/docs/diagrams/layer1-pruning.mmd +45 -0
- package/docs/diagrams/layer2-compaction.mmd +42 -0
- package/docs/proposals/0007-context-management.md +252 -2
- package/docs/proposals/README.md +4 -3
- package/docs/providers.md +3 -3
- package/docs/session-compression.md +695 -0
- package/examples/agent-demo.ts +23 -1
- package/examples/basic.ts +3 -3
- package/package.json +3 -4
- package/src/agent/agent.ts +314 -52
- package/src/agent/types.ts +19 -1
- package/src/checkpointing/checkpoint-manager.ts +48 -0
- package/src/cli/components/App.tsx +553 -34
- package/src/cli/components/CommandSuggestions.tsx +2 -0
- package/src/cli/components/Header.tsx +16 -1
- package/src/cli/components/Messages.tsx +20 -14
- package/src/cli/index.tsx +3 -2
- package/src/config/types.ts +26 -1
- package/src/index.ts +3 -3
- package/src/input/history-manager.ts +289 -0
- package/src/input/index.ts +6 -0
- package/src/prompts/index.test.ts +2 -1
- package/src/prompts/index.ts +3 -3
- package/src/providers/{gemini.ts → google.ts} +69 -18
- package/src/providers/index.ts +14 -14
- package/src/providers/openai.ts +7 -0
- package/src/providers/registry.ts +3 -3
- package/src/providers/types.ts +33 -3
- package/src/session/compression/engine.ts +406 -0
- package/src/session/compression/index.ts +18 -0
- package/src/session/compression/types.ts +102 -0
- package/src/session/manager.ts +326 -3
- package/src/session/types.ts +21 -0
- package/tests/input-history-manager.test.ts +335 -0
- package/tests/session-checkpoint-persistence.test.ts +198 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
%% Layer 1: Tool Output Pruning
|
|
2
|
+
%% Detailed pruneToolOutputs flow
|
|
3
|
+
|
|
4
|
+
flowchart TD
|
|
5
|
+
Start([pruneToolOutputs]) --> CheckMin{total tokens > 20k?}
|
|
6
|
+
CheckMin -->|No| Return0[Return: pruned=false<br/>count=0, saved=0]
|
|
7
|
+
CheckMin -->|Yes| InitVars[Initialize:<br/>protectedTokens = 0<br/>protectedIndices = Set]
|
|
8
|
+
|
|
9
|
+
InitVars --> LoopBackward[Iterate backward<br/>i = length-1 to 0]
|
|
10
|
+
LoopBackward --> CheckMsg{Message contains<br/>tool_result?}
|
|
11
|
+
|
|
12
|
+
CheckMsg -->|No| NextMsg1[Continue to next]
|
|
13
|
+
CheckMsg -->|Yes| CalcMsgTokens[Calculate message tokens]
|
|
14
|
+
|
|
15
|
+
CalcMsgTokens --> CheckProtect{protectedTokens<br/>< 40k?}
|
|
16
|
+
CheckProtect -->|Yes| AddProtected[protectedTokens += msgTokens<br/>protectedIndices.add i]
|
|
17
|
+
CheckProtect -->|No| StopLoop[Stop loop]
|
|
18
|
+
|
|
19
|
+
AddProtected --> NextMsg1
|
|
20
|
+
NextMsg1 --> MoreMsg1{More messages?}
|
|
21
|
+
MoreMsg1 -->|Yes| LoopBackward
|
|
22
|
+
MoreMsg1 -->|No| LoopForward
|
|
23
|
+
|
|
24
|
+
StopLoop --> LoopForward[Iterate forward<br/>i = 0 to length-1]
|
|
25
|
+
LoopForward --> CheckProtected{i in<br/>protectedIndices?}
|
|
26
|
+
|
|
27
|
+
CheckProtected -->|Yes| NextMsg2[Continue to next]
|
|
28
|
+
CheckProtected -->|No| HasToolRes{Contains<br/>tool_result?}
|
|
29
|
+
|
|
30
|
+
HasToolRes -->|No| NextMsg2
|
|
31
|
+
HasToolRes -->|Yes| CalcBefore[Record tokens before clear]
|
|
32
|
+
|
|
33
|
+
CalcBefore --> ClearContent[Clear tool result:<br/>content = Old tool result cleared<br/>pruned = true<br/>prunedAt = ISO timestamp]
|
|
34
|
+
ClearContent --> CalcAfter[Record tokens after clear]
|
|
35
|
+
CalcAfter --> UpdateStats[savedTokens += before - after<br/>prunedCount++]
|
|
36
|
+
|
|
37
|
+
UpdateStats --> NextMsg2
|
|
38
|
+
NextMsg2 --> MoreMsg2{More messages?}
|
|
39
|
+
MoreMsg2 -->|Yes| LoopForward
|
|
40
|
+
MoreMsg2 -->|No| ReturnStats[Return: pruned, count, saved]
|
|
41
|
+
|
|
42
|
+
style CheckMin fill:#fff3e0
|
|
43
|
+
style CheckProtect fill:#fff3e0
|
|
44
|
+
style ClearContent fill:#ffd93d,stroke:#333,stroke-width:2px
|
|
45
|
+
style ReturnStats fill:#51cf66
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
%% Layer 2: Compaction (Summarization)
|
|
2
|
+
%% Detailed compact flow
|
|
3
|
+
|
|
4
|
+
flowchart TD
|
|
5
|
+
Start([compact messages, range]) --> Slice[Extract messages in range<br/>messages.slice start, end+1]
|
|
6
|
+
|
|
7
|
+
Slice --> Par1[Extract info in parallel]
|
|
8
|
+
|
|
9
|
+
Par1 --> ExtFiles[extractFilesModified<br/>Iterate tool_use blocks<br/>Collect Write/Edit file_path]
|
|
10
|
+
Par1 --> ExtTools[extractToolUsage<br/>Count each tool usage<br/>Record top 3 notable uses]
|
|
11
|
+
Par1 --> ExtDecisions[extractKeyDecisions<br/>Find sentences with decision keywords<br/>decided/chose/will use/going with]
|
|
12
|
+
|
|
13
|
+
ExtFiles --> BuildPrompt[Build continuation prompt]
|
|
14
|
+
ExtTools --> BuildPrompt
|
|
15
|
+
ExtDecisions --> BuildPrompt
|
|
16
|
+
|
|
17
|
+
BuildPrompt --> FormatConv[Format conversation history:<br/>role idx: content 500 chars]
|
|
18
|
+
FormatConv --> CreatePrompt[Prompt template:<br/>Provide detailed prompt for continuing...<br/>Focus on:<br/>1. What we accomplished<br/>2. Current work<br/>3. Files modified + changes<br/>4. Next steps<br/>5. Important context/decisions]
|
|
19
|
+
|
|
20
|
+
CreatePrompt --> CallLLM[provider.complete<br/>model: config.model<br/>max_tokens: 1500]
|
|
21
|
+
CallLLM --> ExtractText[Extract text content<br/>from response.content]
|
|
22
|
+
|
|
23
|
+
ExtractText --> CreateSum[Create ConversationSummary]
|
|
24
|
+
CreateSum --> SetID[id: sum-timestamp-random]
|
|
25
|
+
CreateSum --> SetType[type: compaction]
|
|
26
|
+
CreateSum --> SetRange[coveringMessages: start, end]
|
|
27
|
+
CreateSum --> SetContent[content: continuation prompt]
|
|
28
|
+
CreateSum --> SetMeta[metadata: decisions, files, tools]
|
|
29
|
+
CreateSum --> EstTokens[estimatedTokens: content.length / 4]
|
|
30
|
+
CreateSum --> SetTime[generatedAt: ISO timestamp]
|
|
31
|
+
|
|
32
|
+
SetID --> Return[Return ConversationSummary]
|
|
33
|
+
SetType --> Return
|
|
34
|
+
SetRange --> Return
|
|
35
|
+
SetContent --> Return
|
|
36
|
+
SetMeta --> Return
|
|
37
|
+
EstTokens --> Return
|
|
38
|
+
SetTime --> Return
|
|
39
|
+
|
|
40
|
+
style CallLLM fill:#ff6b6b,stroke:#333,stroke-width:2px
|
|
41
|
+
style CreatePrompt fill:#74c0fc
|
|
42
|
+
style Return fill:#51cf66
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
- **Proposal ID**: 0007
|
|
4
4
|
- **Author**: mycode team
|
|
5
|
-
- **Status**:
|
|
5
|
+
- **Status**: Implemented - Pending Verification
|
|
6
6
|
- **Created**: 2025-01-15
|
|
7
|
-
- **Updated**:
|
|
7
|
+
- **Updated**: 2026-01-18
|
|
8
8
|
|
|
9
9
|
## Summary
|
|
10
10
|
|
|
@@ -427,3 +427,253 @@ Existing sessions will work without context stats; stats begin tracking on first
|
|
|
427
427
|
- [Claude Code Context Management](https://code.claude.com/docs/en/context)
|
|
428
428
|
- [OpenAI Tokenizer (tiktoken)](https://github.com/openai/tiktoken)
|
|
429
429
|
- [Anthropic Token Counting](https://docs.anthropic.com/en/docs/tokens)
|
|
430
|
+
|
|
431
|
+
## Implementation Status
|
|
432
|
+
|
|
433
|
+
### ✅ Implemented (Phase 1-3)
|
|
434
|
+
|
|
435
|
+
**Session Compression System**:
|
|
436
|
+
- ✅ `CompressionEngine` class with Layer 1 (Pruning) and Layer 2 (Compaction)
|
|
437
|
+
- Message deduplication and quality scoring
|
|
438
|
+
- Context-aware summarization
|
|
439
|
+
- Intelligent message selection (recent, high-value, tool results)
|
|
440
|
+
- Configurable thresholds and parameters
|
|
441
|
+
- ✅ Integration with `SessionManager`
|
|
442
|
+
- Automatic compression when approaching context limits
|
|
443
|
+
- Compression statistics tracking
|
|
444
|
+
- Persistent compression metadata in session files
|
|
445
|
+
|
|
446
|
+
**CLI Commands**:
|
|
447
|
+
- ✅ `/compact` - Manual conversation compaction
|
|
448
|
+
- Triggers compression immediately
|
|
449
|
+
- Shows statistics (active/total messages, summaries, saved %)
|
|
450
|
+
- Visual ASCII box display with progress bars
|
|
451
|
+
- ✅ `/context` - Context usage statistics
|
|
452
|
+
- Shows active vs total message counts
|
|
453
|
+
- Displays compression status (Compressed/Uncompressed)
|
|
454
|
+
- Progress bar visualization
|
|
455
|
+
- ASCII box display with colored status
|
|
456
|
+
|
|
457
|
+
**UI Rendering Fixes** (2026-01-18):
|
|
458
|
+
- ✅ Fixed info icon "ℹ" appearing on separate line before box output
|
|
459
|
+
- Added box content detection in `renderHistoryItem()` (App.tsx:1389-1396)
|
|
460
|
+
- Box content now renders directly without InfoMessage wrapper
|
|
461
|
+
- ✅ Fixed right border alignment for `/context` and `/compact` commands
|
|
462
|
+
- Corrected padding calculation from `-2` to `-3` (App.tsx:904, 965)
|
|
463
|
+
- All border characters (`+`, `|`) now perfectly aligned
|
|
464
|
+
- Consistent 50-character width across all lines
|
|
465
|
+
|
|
466
|
+
**Visual Output** (After Fixes):
|
|
467
|
+
```
|
|
468
|
+
+------------------------------------------------+
|
|
469
|
+
| Context Usage Statistics |
|
|
470
|
+
+------------------------------------------------+
|
|
471
|
+
| Active Messages 12 |
|
|
472
|
+
| Total Messages 45 |
|
|
473
|
+
| Summaries 2 |
|
|
474
|
+
| |
|
|
475
|
+
| Usage [#####...............] 27% |
|
|
476
|
+
| |
|
|
477
|
+
| Status: Compressed |
|
|
478
|
+
+------------------------------------------------+
|
|
479
|
+
```
|
|
480
|
+
|
|
481
|
+
### ✅ Newly Implemented (2026-01-18 - Pending Verification)
|
|
482
|
+
|
|
483
|
+
**Token Counting & Tracking**:
|
|
484
|
+
- ✅ **Cumulative token tracking** from API responses
|
|
485
|
+
- `SessionManager.cumulativeTokens` tracks input/output/total
|
|
486
|
+
- `calculateCumulativeTokens()` sums from session metadata
|
|
487
|
+
- `updateTokenUsageFromLatestCompletion()` for incremental updates
|
|
488
|
+
- `getTokenUsage()` public getter for current usage
|
|
489
|
+
- Persisted to `session.metadata.tokenUsage` on save
|
|
490
|
+
- ✅ **Actual API token usage** instead of 4:1 estimates
|
|
491
|
+
- Token usage passed to `CompressionEngine.needsCompression()`
|
|
492
|
+
- Uses provider-returned `inputTokens` and `outputTokens`
|
|
493
|
+
- Falls back to 4:1 estimate if API doesn't return usage
|
|
494
|
+
|
|
495
|
+
**Auto-Compaction with Thresholds**:
|
|
496
|
+
- ✅ **Threshold-based compression triggering**
|
|
497
|
+
- 80% warning threshold: emits `context-warning` event
|
|
498
|
+
- 90% auto-compact threshold: triggers compression automatically
|
|
499
|
+
- Returns `usagePercent` and `shouldWarn` flags from `needsCompression()`
|
|
500
|
+
- ✅ **Event-driven architecture** with EventEmitter
|
|
501
|
+
- `context-warning` - Emitted at 80% usage
|
|
502
|
+
- `auto-compacting` - Emitted before compression at 90%
|
|
503
|
+
- `compaction-complete` - Emitted after compression finishes
|
|
504
|
+
- ✅ **User feedback in UI**
|
|
505
|
+
- ⚠️ "Context usage at 82% - Consider using /compact"
|
|
506
|
+
- 📦 "Auto-compacting (91% usage, strategy: prune)..."
|
|
507
|
+
- ✓ "Compaction complete (prune)"
|
|
508
|
+
- Smart warning deduplication (shows once per session)
|
|
509
|
+
|
|
510
|
+
**Status Display**:
|
|
511
|
+
- ✅ **Context usage in header**
|
|
512
|
+
- Format: `Context: 45/120 msgs (37%)`
|
|
513
|
+
- Real-time updates after each completion
|
|
514
|
+
- Only shown when activeMessages > 0
|
|
515
|
+
- Calculates percentage from actual token usage vs context window
|
|
516
|
+
- ✅ **Real-time token tracking**
|
|
517
|
+
- Header refreshes on every render
|
|
518
|
+
- Pulls from `SessionManager.getTokenUsage()` and `getCompressionStats()`
|
|
519
|
+
|
|
520
|
+
**Implementation Details**:
|
|
521
|
+
- ✅ **Files Modified**:
|
|
522
|
+
- `src/session/manager.ts` - Token tracking, event emission
|
|
523
|
+
- `src/session/compression/engine.ts` - Threshold logic
|
|
524
|
+
- `src/cli/components/Header.tsx` - Context stats display
|
|
525
|
+
- `src/cli/components/App.tsx` - Event listeners, header updates
|
|
526
|
+
- ✅ **Backward Compatible**: Works with existing sessions
|
|
527
|
+
- ✅ **Build Status**: TypeScript compilation successful
|
|
528
|
+
|
|
529
|
+
### ❌ Not Implemented (Deferred - Low Priority)
|
|
530
|
+
|
|
531
|
+
**Provider-Specific Tokenizers**:
|
|
532
|
+
- ❌ Client-side tokenizer implementations
|
|
533
|
+
- No OpenAITokenizer, AnthropicTokenizer, or GeminiTokenizer classes
|
|
534
|
+
- Not needed: Using actual API token counts instead
|
|
535
|
+
- Could be added later for pre-submission estimates
|
|
536
|
+
- **Decision**: Deferred - API usage is more accurate
|
|
537
|
+
|
|
538
|
+
**Memory Tool**:
|
|
539
|
+
- ❌ Claude Code-style Memory Tool implementation
|
|
540
|
+
- No persistent storage across context resets
|
|
541
|
+
- Memory system exists but uses different approach (GEN.md files)
|
|
542
|
+
- **Decision**: Out of scope for this proposal
|
|
543
|
+
|
|
544
|
+
### 📋 Verification & Testing Required
|
|
545
|
+
|
|
546
|
+
**Core functionality implemented - needs real-world testing:**
|
|
547
|
+
|
|
548
|
+
1. **Verification Tasks** (High Priority):
|
|
549
|
+
- ✅ Build successful - TypeScript compilation passed
|
|
550
|
+
- ⏳ **Test 80% warning trigger** - Start long conversation and verify warning appears
|
|
551
|
+
- ⏳ **Test 90% auto-compact** - Continue until auto-compaction triggers
|
|
552
|
+
- ⏳ **Verify token accuracy** - Compare displayed tokens vs API actual usage
|
|
553
|
+
- ⏳ **Test header display** - Confirm context stats update in real-time
|
|
554
|
+
- ⏳ **Test session persistence** - Reload session and verify token counts preserved
|
|
555
|
+
- ⏳ **Test event deduplication** - Verify warning only shows once per session
|
|
556
|
+
|
|
557
|
+
2. **Edge Cases to Test**:
|
|
558
|
+
- Session load with no token usage data (backward compatibility)
|
|
559
|
+
- Session fork inherits correct token counts
|
|
560
|
+
- Compression resets warning flag after compaction
|
|
561
|
+
- Multiple rapid completions don't spam warnings
|
|
562
|
+
- Very short sessions (< 10 messages) display correctly
|
|
563
|
+
|
|
564
|
+
3. **Future Optimizations** (Low Priority - Post-Verification):
|
|
565
|
+
- Advanced compaction strategies
|
|
566
|
+
- Better summarization quality
|
|
567
|
+
- Provider-specific tokenizers for pre-submission estimates
|
|
568
|
+
- Memory tool integration
|
|
569
|
+
|
|
570
|
+
### 📁 Implementation Files
|
|
571
|
+
|
|
572
|
+
| File | Status | Notes |
|
|
573
|
+
|------|--------|-------|
|
|
574
|
+
| `src/session/compression/engine.ts` | ✅ Complete | Layer 1 & 2 compression + threshold logic |
|
|
575
|
+
| `src/session/compression/types.ts` | ✅ Complete | All compression types |
|
|
576
|
+
| `src/session/compression/index.ts` | ✅ Complete | Module exports |
|
|
577
|
+
| `src/session/manager.ts` | ✅ Modified | Token tracking + EventEmitter + compression |
|
|
578
|
+
| `src/session/types.ts` | ✅ Modified | Token usage in metadata |
|
|
579
|
+
| `src/cli/components/App.tsx` | ✅ Modified | Event listeners + header stats |
|
|
580
|
+
| `src/cli/components/Header.tsx` | ✅ Modified | Context stats display |
|
|
581
|
+
| `src/context/tokenizer.ts` | ⏸️ Deferred | Using API token counts instead |
|
|
582
|
+
| `src/context/context-manager.ts` | ⏸️ Deferred | Context tracking in SessionManager |
|
|
583
|
+
|
|
584
|
+
### 🐛 Bug Fixes
|
|
585
|
+
|
|
586
|
+
**UI Rendering Issues** (Fixed 2026-01-18):
|
|
587
|
+
|
|
588
|
+
**Problem 1**: Info icon "ℹ" appearing on separate line before box output
|
|
589
|
+
- **Root Cause**: `InfoMessage` component always prepended icon, causing it to appear on separate line
|
|
590
|
+
- **Solution**: Added box content detection (`content.trim().startsWith('+---')`) in `renderHistoryItem()`
|
|
591
|
+
- **Files Changed**: `src/cli/components/App.tsx` (lines 1389-1396)
|
|
592
|
+
|
|
593
|
+
**Problem 2**: Right border `|` not aligned properly
|
|
594
|
+
- **Root Cause**: Padding calculation was off by 1 character
|
|
595
|
+
- **Before**: `w - text.length - 2` and `w - visible - 2`
|
|
596
|
+
- **After**: `w - text.length - 3` and `w - visible - 3`
|
|
597
|
+
- **Explanation**: Border line `'| ' + pad(text) + '|'` = 2 + pad + 1 = w, so pad = w - 3
|
|
598
|
+
- **Files Changed**: `src/cli/components/App.tsx` (lines 904, 965)
|
|
599
|
+
|
|
600
|
+
**Test Results**:
|
|
601
|
+
```
|
|
602
|
+
✅ All lines same length: true
|
|
603
|
+
✅ Expected: 50, Actual: 50
|
|
604
|
+
✅ /compact box: Passed
|
|
605
|
+
✅ /context box: Passed
|
|
606
|
+
✅ No info icon in output
|
|
607
|
+
✅ Perfect border alignment
|
|
608
|
+
```
|
|
609
|
+
|
|
610
|
+
---
|
|
611
|
+
|
|
612
|
+
## 📦 Latest Implementation (2026-01-18)
|
|
613
|
+
|
|
614
|
+
### Summary
|
|
615
|
+
|
|
616
|
+
Completed all high-priority features from the "Remaining Work" section:
|
|
617
|
+
- ✅ Accurate token tracking from API responses
|
|
618
|
+
- ✅ 80% warning threshold + 90% auto-compaction
|
|
619
|
+
- ✅ Real-time context display in header
|
|
620
|
+
- ✅ Event-driven architecture for extensibility
|
|
621
|
+
|
|
622
|
+
### Implementation Phases
|
|
623
|
+
|
|
624
|
+
**Phase 1: Token Usage Tracking** (~30 min)
|
|
625
|
+
- Added cumulative token tracking to SessionManager
|
|
626
|
+
- Implemented token calculation from session metadata
|
|
627
|
+
- Updated compression to use actual API token counts
|
|
628
|
+
- Added public `getTokenUsage()` getter
|
|
629
|
+
|
|
630
|
+
**Phase 2: Threshold Warnings** (~45 min)
|
|
631
|
+
- Modified `needsCompression()` to return usage % and warning flags
|
|
632
|
+
- Extended SessionManager with EventEmitter
|
|
633
|
+
- Implemented 3 events: `context-warning`, `auto-compacting`, `compaction-complete`
|
|
634
|
+
- Added UI event listeners with smart deduplication
|
|
635
|
+
|
|
636
|
+
**Phase 3: Context Display** (~30 min)
|
|
637
|
+
- Updated Header component with optional context stats
|
|
638
|
+
- Real-time header updates showing "Context: X/Y msgs (Z%)"
|
|
639
|
+
- Only displays when activeMessages > 0
|
|
640
|
+
|
|
641
|
+
### Code Changes
|
|
642
|
+
|
|
643
|
+
**Total**: ~105 lines across 4 files
|
|
644
|
+
|
|
645
|
+
| File | Changes | Lines |
|
|
646
|
+
|------|---------|-------|
|
|
647
|
+
| `src/session/manager.ts` | Token tracking, events, getters | +65 |
|
|
648
|
+
| `src/session/compression/engine.ts` | Threshold logic | +15 |
|
|
649
|
+
| `src/cli/components/Header.tsx` | Context stats display | +15 |
|
|
650
|
+
| `src/cli/components/App.tsx` | Event listeners, header stats | +40 |
|
|
651
|
+
|
|
652
|
+
### Key Design Decisions
|
|
653
|
+
|
|
654
|
+
1. **API Token Counts over Tokenizers**
|
|
655
|
+
- Using actual usage from API responses instead of client-side estimation
|
|
656
|
+
- More accurate, no external dependencies (tiktoken, etc.)
|
|
657
|
+
- Falls back to 4:1 estimate if API doesn't provide usage
|
|
658
|
+
|
|
659
|
+
2. **Event-Driven Architecture**
|
|
660
|
+
- SessionManager extends EventEmitter
|
|
661
|
+
- Loosely coupled: compression engine doesn't need UI knowledge
|
|
662
|
+
- Easy to add more listeners (logging, analytics, etc.)
|
|
663
|
+
|
|
664
|
+
3. **Smart Warning Deduplication**
|
|
665
|
+
- Warning only shown once per session using `contextWarningShownRef`
|
|
666
|
+
- Resets after compaction completes
|
|
667
|
+
- Prevents spam during long conversations
|
|
668
|
+
|
|
669
|
+
### Testing Required
|
|
670
|
+
|
|
671
|
+
See "📋 Verification & Testing Required" section above for:
|
|
672
|
+
- Functional tests (80% warning, 90% auto-compact)
|
|
673
|
+
- Edge cases (session load, fork, persistence)
|
|
674
|
+
- Real-world usage validation
|
|
675
|
+
|
|
676
|
+
### References
|
|
677
|
+
|
|
678
|
+
Implementation plan: `STREAMING_IMPLEMENTATION_SUMMARY.md` (Phase 4 context management)
|
|
679
|
+
Related proposal: `0007-context-management.md` (this document)
|
package/docs/proposals/README.md
CHANGED
|
@@ -8,7 +8,8 @@ This directory contains enhancement proposals for the gencode project. Each prop
|
|
|
8
8
|
2. **Under Review**: Community and maintainer review
|
|
9
9
|
3. **Accepted**: Approved for implementation
|
|
10
10
|
4. **Implemented**: Feature has been implemented
|
|
11
|
-
5. **
|
|
11
|
+
5. **Implemented ⚠️**: Implemented but not fully verified/tested
|
|
12
|
+
6. **Rejected**: Proposal was rejected with explanation
|
|
12
13
|
|
|
13
14
|
## Proposal Index
|
|
14
15
|
|
|
@@ -22,8 +23,8 @@ This directory contains enhancement proposals for the gencode project. Each prop
|
|
|
22
23
|
| [0004](./0004-plan-mode.md) | Plan Mode | Implemented |
|
|
23
24
|
| [0005](./0005-todo-system.md) | Todo System | Implemented |
|
|
24
25
|
| [0006](./0006-memory-system.md) | Memory System (MYCODE.md) | Implemented |
|
|
25
|
-
| [0007](./0007-context-management.md) | Context Management |
|
|
26
|
-
| [0008](./0008-checkpointing.md) | Checkpointing |
|
|
26
|
+
| [0007](./0007-context-management.md) | Context Management | Implemented ⚠️ |
|
|
27
|
+
| [0008](./0008-checkpointing.md) | Checkpointing | Implemented ⚠️ |
|
|
27
28
|
| [0009](./0009-hooks-system.md) | Hooks System | Draft |
|
|
28
29
|
| [0010](./0010-mcp-integration.md) | MCP Integration | Draft |
|
|
29
30
|
| [0021](./0021-skills-system.md) | Skills System | Draft |
|
package/docs/providers.md
CHANGED
|
@@ -22,9 +22,9 @@ GPT models from OpenAI:
|
|
|
22
22
|
|-------------------|----------------------|-------------|
|
|
23
23
|
| API Key | `OPENAI_API_KEY` | Direct API access |
|
|
24
24
|
|
|
25
|
-
### Google
|
|
25
|
+
### Google
|
|
26
26
|
|
|
27
|
-
Gemini models
|
|
27
|
+
Google Generative AI (Gemini models):
|
|
28
28
|
|
|
29
29
|
| Connection Method | Environment Variables | Description |
|
|
30
30
|
|-------------------|----------------------|-------------|
|
|
@@ -182,7 +182,7 @@ gcloud services enable aiplatform.googleapis.com
|
|
|
182
182
|
|
|
183
183
|
GenCode uses a two-layer provider architecture:
|
|
184
184
|
|
|
185
|
-
- **Layer 1: Provider** (Semantic layer) - `anthropic` | `openai` | `
|
|
185
|
+
- **Layer 1: Provider** (Semantic layer) - `anthropic` | `openai` | `google`
|
|
186
186
|
- **Layer 2: AuthMethod** (Implementation layer) - `api_key` | `vertex` | `bedrock` | `azure`
|
|
187
187
|
|
|
188
188
|
Each provider can support multiple authentication methods. For example, Anthropic supports:
|