Skip to content

feat: Claude Code + Claw Code patterns transfer#148

Merged
VictorGjn merged 7 commits intomasterfrom
feat/claude-code-patterns
Apr 2, 2026
Merged

feat: Claude Code + Claw Code patterns transfer#148
VictorGjn merged 7 commits intomasterfrom
feat/claude-code-patterns

Conversation

@VictorGjn
Copy link
Copy Markdown
Owner

Claude Code & Claw Code Patterns Transfer

Transfers context engineering patterns from Claude Code analysis + claw-code clean-room rewrite into modular-patchbay.

Phase 1 (Claude Code leak — Mar 31)

  • System Prompt Builder — static/dynamic boundary for prompt caching (SystemPromptBuilder.ts)
  • Reactive Compaction — dynamic depth adjustment based on runtime signals (ReactiveCompaction.ts)
  • Context Collapse — smart compression preserving structure (ContextCollapse.ts)
  • Tool Use Summary — compact tool output summaries (ToolUseSummary.ts)
  • Agent Search — semantic agent discovery (AgentSearch.ts)
  • Memory Store — session memory pipeline (MemoryStore.ts)
  • Pipeline integration — all wired into existing context assembler + pipeline

Phase 2 (Claw Code rewrite — Apr 1)

  • Prompt Router — fuzzy token scoring selects relevant tools per turn, not the full registry (PromptRouter.ts)
  • Transcript Compaction — sliding window with key decision protection (TranscriptCompaction.ts)
  • Permission Gate — denied tools removed from context + trust-gated init (PermissionGate.ts)

Moat impact

Feature User value
Prompt Router Better answers — less noise in context window
Transcript Compaction Longer sessions — conversations don't degrade
Permission Gate Safety moat — model can't hallucinate blocked tools

Test coverage

  • Unit tests for all new modules
  • Integration + E2E tests for pipeline

Files changed

  • 53 files added/modified across 30 commits

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ef2cb4fe6f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +33 to +34
.replace(/[^a-z0-9s/_-]/g, '')
.split(/[s/_-]+/)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Split prompt tokens on whitespace

The tokenizer regexes use s instead of \s, so prompts are split on the literal letter s rather than whitespace. That means multi-word queries often stay as one token (and words containing s get fragmented), which makes routePrompt miss relevant tools or rank them incorrectly for normal user inputs like "read file" or "show git diff".

Useful? React with 👍 / 👎.

Comment on lines +73 to +74
for (let i = half; i < sorted.length; i++) {
const f = sorted[i];
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Downgrade least-relevant files under token pressure

Because files are sorted ascending by relevance, iterating from half to the end downgrades the most relevant half instead of the least relevant half. Under token pressure this strips detail from the files you most want to preserve, which directly harms answer quality and makes compaction behavior opposite to the intent in the comment.

Useful? React with 👍 / 👎.

const baseTokens = oldRatio > 0 ? item.tokens / oldRatio : item.tokens;
const newTokens = Math.max(1, Math.ceil(baseTokens * newRatio));
newTotal += newTokens;
return { ...item, depth: newDepthNumeric, tokens: newTokens };
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Recompute packed content after depth adjustment

This updates depth and tokens but keeps the original content, so reactive compaction can report a shallow depth while still sending deeper content to the model. In practice that breaks token-budget assumptions and can exceed context limits because the actual text no longer matches the recalculated token estimate.

Useful? React with 👍 / 👎.

Comment on lines +46 to +47
const hash = JSON.stringify(agents.map(a => a.id).sort());
if (!_searchInstance || hash !== _lastIndexHash) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reindex search when agent metadata changes

The cache key only includes sorted agent IDs, so changes to descriptions, roles, tags, capabilities, or any knowledge source content do not trigger a rebuild. That leaves AgentSearch serving stale TF-IDF scores until reindex() is called manually, which makes search results incorrect after normal metadata edits.

Useful? React with 👍 / 👎.

…ction, memory pipeline, context collapse, tool summary, agent search)
…compaction, memory, collapse, tool summary, search
…nner, E2E tests

- Task 1: SystemPromptBuilder wired into systemFrameBuilder (buildSystemFrameOptimized)
- Task 2: ReactiveCompaction wired into packer (packContextReactive)
- Task 3: MemoryStore wired into contextAssembler (assemblePipelineContextWithMemory)
- Task 4: ContextMiddleware wired into pipeline (middleware option)
- Task 5: AgentSearch endpoint added to agents route (GET /agents/search)
- Task 6: WorktreeManager connected to teamRunner (prepareAgentWorktree)
- Task 7: E2E tests for pipeline and team-worktree integration
- Task 8: Barrel export updated (src/claude-code-patterns/index.ts)
- Fix: Removed duplicate Repository block in teamRunner
Transferred from claw-code clean-room rewrite analysis:
- Fuzzy Prompt Routing (only relevant tools injected per turn — better answers)
- Transcript Compaction (sliding window + key decision protection — longer sessions)
- Permission Gate (denied tools removed from context, trust-gated init — safety moat)
- 5 adapter files in src/adapters/ (systemPrompt, reactivePacker, memory, contextMiddleware, search)
- Updated barrel export in src/claude-code-patterns/index.ts with Phase 2 adapters
- Integration tests for all 5 adapters in tests/unit/claude-code-phase2-adapters.test.ts
- Zero modifications to existing files (adapter/wrapper pattern)
@VictorGjn VictorGjn force-pushed the feat/claude-code-patterns branch from 0e2131a to 4cf4dbd Compare April 2, 2026 08:01
@VictorGjn VictorGjn merged commit da14857 into master Apr 2, 2026
@VictorGjn
Copy link
Copy Markdown
Owner Author

Codex Review Fixes (all 4 issues)

# Severity File Fix
1 P1 PromptRouter.ts Regex s\s for whitespace splitting
2 P1 ReactiveCompaction.ts Iterate 0..half (least relevant) instead of half..end (most relevant)
3 P1 reactivePackerWrapper.ts Truncate content proportionally after depth adjustment
4 P2 agentSearchIntegration.ts Include description+role+tags in cache key hash

VictorGjn added a commit that referenced this pull request Apr 2, 2026
- Fix PromptRouter regex: \s not s for whitespace splitting
- Fix ReactiveCompaction: downgrade least-relevant half, not most-relevant
- Fix reactivePackerWrapper: truncate content after depth adjustment
- Fix agentSearchIntegration: include metadata in cache key for freshness
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant