feat(grounding): add ts-autocode-grounding package upstreamed from HoBo - #24
Conversation
…discovery Add a provider-neutral grounding package upstreamed from HoBo's training layer: @intent/@returns/@description/param decorators with dual stage-3/ legacy dispatch, class finalization against a host-provided registry, component metadata composition, an AST-based scanner for ambient @trainable class declarations (replacing downstream regex parsing), a registration-source emitter with configurable header/runtime module, and deterministic text helpers (stableStringify, digest, pascalCase, union) pinned by golden tests. Also record an `exported` flag on TrainableTarget so consumers can filter directive-marked free functions to exported ones. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CgjCQ7r2tJH89PqZDU1DrV
|
Warning Review limit reached
Next review available in: 34 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (6)
📝 WalkthroughWalkthroughAdds a new ChangesGrounding package
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant TypeScriptSource
participant scanDeclaredTrainables
participant generateDeclaredRegistrations
participant training.define
TypeScriptSource->>scanDeclaredTrainables: decorated class source
scanDeclaredTrainables->>generateDeclaredRegistrations: declared operations and contracts
generateDeclaredRegistrations->>training.define: generated registration source
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
packages/grounding/tsconfig.test.json (1)
4-6: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value
"outDir": nullis unnecessary withnoEmit: true.Since
noEmitalready suppresses all emission,outDirhas no effect here; TypeScript tooling may still flagnullas a type mismatch (expects a string) in editors. Consider just omitting the key instead.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/grounding/tsconfig.test.json` around lines 4 - 6, Remove the unnecessary outDir setting from the test TypeScript configuration, leaving noEmit enabled to suppress output. Preserve the existing rootDir and other compiler options.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/grounding/src/decorators.ts`:
- Around line 126-155: Update the `description` function’s
`Object.defineProperty` calls for `description` and `example` to define both
properties as enumerable, preserving the existing conditional creation of
`example` so spread, serialization, and `Object.keys` expose the
FieldDescription values.
In `@packages/grounding/src/scan.ts`:
- Around line 88-113: Update scanOperations to validate each method name before
pushing a DeclaredOperation: throw a clear error when memberName yields a
non-identifier or when the name has already been seen in the class, including
the offending method name in the message. Track names locally within
scanOperations, while preserving normal operation collection for unique valid
identifiers.
In `@packages/grounding/src/text.ts`:
- Around line 45-48: Update the text normalization chain in the visible
formatting function to convert standalone carriage returns to line feeds as well
as CRLF sequences. Ensure all line endings are normalized to LF before trailing
whitespace cleanup and the final newline are applied, preserving digest parity.
---
Nitpick comments:
In `@packages/grounding/tsconfig.test.json`:
- Around line 4-6: Remove the unnecessary outDir setting from the test
TypeScript configuration, leaving noEmit enabled to suppress output. Preserve
the existing rootDir and other compiler options.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 9cd0dda9-a073-493b-9412-93927b0957a0
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (15)
package.jsonpackages/grounding/package.jsonpackages/grounding/src/component.tspackages/grounding/src/decorators.tspackages/grounding/src/index.tspackages/grounding/src/scan.tspackages/grounding/src/text.tspackages/grounding/test/decorators.test.tspackages/grounding/test/scan.test.tspackages/grounding/test/text.test.tspackages/grounding/tsconfig.jsonpackages/grounding/tsconfig.test.jsonpackages/training/src/source.tssrc/grounding.tsvitest.config.ts
| return `${value | ||
| .replace(/\r\n/g, "\n") | ||
| .replace(/[ \t]+$/gm, "") | ||
| .replace(/\s+$/u, "")}\n`; |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Normalize lone CR line endings too.
Line 46 handles CRLF but preserves standalone \r, so LF-only output and digest parity are not guaranteed.
Proposed fix
- .replace(/\r\n/g, "\n")
+ .replace(/\r\n?/g, "\n")📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| return `${value | |
| .replace(/\r\n/g, "\n") | |
| .replace(/[ \t]+$/gm, "") | |
| .replace(/\s+$/u, "")}\n`; | |
| return `${value | |
| .replace(/\r\n?/g, "\n") | |
| .replace(/[ \t]+$/gm, "") | |
| .replace(/\s+$/u, "")}\n`; |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/grounding/src/text.ts` around lines 45 - 48, Update the text
normalization chain in the visible formatting function to convert standalone
carriage returns to line feeds as well as CRLF sequences. Ensure all line
endings are normalized to LF before trailing whitespace cleanup and the final
newline are applied, preserving digest parity.
…e description fields Scanned operation names become `export const <name>` in generated registrations, so ambient overload signatures or computed member names would silently corrupt the emitted file — refuse loudly instead. Also make description()'s FieldDescription properties enumerable so spread, serialization, and Object.keys expose them. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CgjCQ7r2tJH89PqZDU1DrV
|
Addressed the review in 719997e: Two items intentionally skipped:
Generated by Claude Code |
TC39 stage-3 decorators only: intent/returns are plain stage-3 method decorators, description() is a plain FieldDescription factory (param is an alias), and the legacy prototype-keyed pending registry, parameter decorator shim, and granularLegacyOptions are removed. No v1 exists; no previous patterns to support. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CgjCQ7r2tJH89PqZDU1DrV
Summary
Upstreams HoBo's reusable TypeScript-codegen layer into a new provider-neutral package,
ts-autocode-grounding(packages/grounding), respecting the sibling-isolation rule (no imports of root or sibling packages):src/decorators.ts— granular grounding decorators@intent,@returns,@description, plusparam()and composition helpers (composeOptions,granularOptionsFor,granularLegacyOptions). Dual-mode dispatch (TC39 stage-3 and legacyexperimentalDecoratorscall shapes).src/component.ts— class-level finalization (finalizeTrainableClass) against a host-providedGroundingRegistry, and component-metadata composition (createComponentDecorator,componentMetadataOf) parameterized by metadata symbols so any host runtime can wire its own.src/scan.ts— AST-based scanner (scanDeclaredTrainables) for ambient@trainable declare classdeclarations — replaces downstream regex parsing — plusgenerateDeclaredRegistrationswith configurable header/runtime-module emission.src/text.ts— deterministic text helpers (stableStringify,normalizeText,digest,pascalCase,camelCase,union) pinned by golden tests so downstream byte-for-byte digest parity holds.Also adds an
exportedflag toTrainableTargetints-autocode-trainingso consumers can filter directive-marked free functions to exported ones (additive; free-functionexportmodifier detection, always false for class methods).Root wiring:
ts-autocode/groundingsubpath export,build:groundingfirst in the ordered build, typecheck + vitest coverage.Test plan
npm run check— typecheck all five projects, vitest (20 files / 112 tests, including newpackages/grounding/test/suites for decorators, scanning/emission, and golden text values), ordered build.Generated by Claude Code
Summary by CodeRabbit
New Features
Tests