feat(ttsr): Port Time Traveling Streamed Rules from oh-my-pi#2275
Draft
minpeter wants to merge 11 commits intocode-yeongyu:devfrom
Draft
feat(ttsr): Port Time Traveling Streamed Rules from oh-my-pi#2275minpeter wants to merge 11 commits intocode-yeongyu:devfrom
minpeter wants to merge 11 commits intocode-yeongyu:devfrom
Conversation
…, and barrel export
…el, session hooks, event dispatch)
…e discovery race, maxRetriesPerRule enforcement - Call markInjected() via hookInstance mutable reference in onMatch callback to fix repeatMode 'once' infinite retry loops - Add addRulesToExistingManagers() to TtsrHook interface and implementation to inject discovered rules into already-initialized session managers - Enforce maxRetriesPerRule with retryCounts Map in abort-retry-handler, filtering eligible rules before triggering abort-retry cycle - Add clearRetryCounts() for session cleanup - Add tests for all three bug fixes (73 pass, 0 fail)
…tch blocks
- Fix interruptMode fallback: 'abort-retry' → 'always' (matches Zod schema default)
- Fix repeatGap fallback: 3 → 10 (matches Zod schema default)
- Replace 3 empty .catch(() => {}) with proper log() calls for abort, prompt, and rule discovery
- Update schema.json (regenerated by build)
Ship a default TTSR rule that detects GPT models outputting 'multi_tool_use.parallel' (not a real tool in this environment) and triggers abort-retry with a corrective system interrupt. - Add createBuiltinTtsrRules() factory in builtin-rules.ts - Pre-populate TTSR rules array with built-in defaults - User-discovered rules from .claude/rules/ etc. append on top - Built-in rule can be overridden by same-name user rule
Allow `"ttsr": true` as shorthand for `"ttsr": { "enabled": true }`.
Boolean values are transformed to full config objects with all defaults.
Existing object-form config continues to work unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Port the full TTSR (Time Traveling Streamed Rules) system from
can1357/oh-my-pito oh-my-opencode. TTSR monitors LLM output streams in real-time for regex patterns, aborts the stream on match, injects a<system-interrupt>corrective prompt, and retries automatically.Primary use case:
gpt-5.3-codexoutputsto=multi_tool_use.parallelinstead of proper tool calls — TTSR detects this, stops, injects a reminder, and retries.What's Included
New Modules (
src/features/ttsr/)TtsrMatchSource,TtsrMatchContext,TtsrScope,TtsrEntry,TtsrSettings,TtsrRulerepeatMode("once"/"after-gap"),markInjected()trackingtext,tool:edit,tool:edit(*.rs)) with picomatch glob supportparseFrontmatter()<system-interrupt reason="rule_violation">XML templatesNew Hooks (
src/hooks/ttsr/)createTtsrHook()factory: listens tosession.created/deleted,message.updated,message.part.updated; delegates to TtsrManager for stream monitoringmaxRetriesPerRuleenforcement andretryCountstracking.ttsrrule files from.claude/rules/,.opencode/rules/,~/.claude/rules/Plugin Wiring (minimal, scoped changes)
src/config/schema/ttsr.ts— Zod v4 config schema (6 fields: enabled, contextMode, interruptMode, repeatMode, repeatGap, maxRetriesPerRule)src/config/schema/oh-my-opencode-config.ts— Addedttsroptional fieldsrc/config/schema/hooks.ts— Added"ttsr"to HookNameSchemasrc/hooks/index.ts— Barrel export forcreateTtsrHook+TtsrHooksrc/plugin/hooks/create-session-hooks.ts— TTSR hook registration with abort/prompt wiringsrc/plugin/event.ts— 1-line dispatch additionTest Coverage
Bug Fixes (discovered during QA)
markInjected()never called — Fixed viahookInstancemutable reference pattern. Without this,repeatMode: "once"caused infinite retry loopsaddRulesToExistingManagers()to inject discovered rules into already-initialized session managersmaxRetriesPerRulenot enforced — AddedretryCountsMap with per-session, per-rule trackinginterruptModefallback corrected to"always",repeatGapto10(matching Zod defaults).catch(() => {})with properlog()callsStats
as any/@ts-ignore/@ts-expect-errorparseFrontmatter(),log(),safeHook(), factory patternConfiguration
Commits
da3eb1a6feat(ttsr): add TTSR types, config schema, and interrupt templatea8830233feat(ttsr): implement TtsrManager, scope parser, and rule parser with TDD2ec5edc1feat(ttsr): implement abort-retry handler, rule discovery, hook tests, and barrel exporta912eea7feat(ttsr): register TTSR hook into plugin system525069fatest(ttsr): add end-to-end integration test43c33e98fix(ttsr): add missing hook.tse5429f46fix(ttsr): resolve three critical bugs02a9939bfix(ttsr): correct wiring fallback values and add error loggingSummary by cubic
Adds Time Traveling Streamed Rules (TTSR) to monitor assistant output in real time, abort on rule violations, inject a system-interrupt prompt, and retry. TTSR is disabled by default (opt-in) and ships a built-in guard that blocks codex-style plain text tool syntax like "multi_tool_use.parallel".
New Features
Bug Fixes
Written for commit ad113c2. Summary will update on new commits.