Skip to content

refactor: use shared @chittyos/schema scope-projector#103

Merged
chitcommit merged 1 commit intomainfrom
refactor/scope-projector-shared-lib
Apr 24, 2026
Merged

refactor: use shared @chittyos/schema scope-projector#103
chitcommit merged 1 commit intomainfrom
refactor/scope-projector-shared-lib

Conversation

@chitcommit
Copy link
Copy Markdown
Contributor

@chitcommit chitcommit commented Apr 24, 2026

Summary

  • Replace inline fractal scope projection in central-workflows.ts with thin adapter over @chittyos/schema/scope-projector
  • Reduces 175 → 59 lines — SQL upsert, status mapping, and types now shared across services via chittyschema
  • Adds @chittyos/schema as local file dependency (linked to ../../CHITTYFOUNDATION/chittyschema)

Test plan

  • npm run check passes (type-check)
  • Scope projection still fires on workflow events (verify via Neon public.scopes table)
  • No runtime errors in Workers deploy

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
    • Refactored scope projection implementation to leverage a centralized schema library, improving code organization and maintainability. All existing functionality and public APIs remain unchanged.

Replace inline fractal scope projection with thin adapter over the shared
@chittyos/schema/scope-projector library. Reduces central-workflows.ts
from 175 to 59 lines — the SQL upsert, status mapping, and type
definitions now live in chittyschema and are reused across services.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 24, 2026 08:13
@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
❌ Deployment failed
View logs
chittyfinance e5904b7 Apr 24 2026, 08:13 AM

@chitcommit chitcommit enabled auto-merge (squash) April 24, 2026 08:13
@github-actions
Copy link
Copy Markdown
Contributor

@coderabbitai review

Please evaluate:

  • Security implications
  • Credential exposure risk
  • Dependency supply chain concerns
  • Breaking API changes

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 24, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

The pull request introduces a new workspace dependency (@chittyos/schema) and refactors the scope projection logic in the central workflows module from a local SQL-based implementation to an external schema library adapter, while maintaining the existing public API signature and fire-and-forget behavior.

Changes

Cohort / File(s) Summary
Dependency Management
package.json
Adds @chittyos/schema as a runtime dependency sourced from local workspace path.
Scope Projection Refactor
server/lib/central-workflows.ts
Removes local SQL "fractal" upsert implementation and enum typings; delegates to @chittyos/schema/scope-projector. The scopeLog function now constructs a projector payload (injecting tenantId into metadata) and invokes a preconfigured financeProjector. Re-exports SCOPE_TYPES, ScopeStatus, ScopeCharacterization, and ScopeEnv types from the external library.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 A new schema hops into view,
SQL fractures fade, refactored anew,
The projector gleams, delegation rings true,
Metadata whispers through tenantId too,
Fire-and-forget still works, tried and steady—
One signature unchanged, the new dance is ready! 🎭✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'refactor: use shared @chittyos/schema scope-projector' directly and specifically describes the main change: replacing inline scope projection with a shared library adapter.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/scope-projector-shared-lib

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@chitcommit chitcommit merged commit a497b0b into main Apr 24, 2026
11 of 15 checks passed
@chitcommit chitcommit deleted the refactor/scope-projector-shared-lib branch April 24, 2026 08:14
@claude
Copy link
Copy Markdown

claude Bot commented Apr 24, 2026

Code Review — PR #103: refactor: use shared @chittyos/schema scope-projector

Overview: This PR replaces 116 lines of inline scope-projection logic (SQL upsert, status mapping, type defs) with a thin adapter over a shared @chittyos/schema/scope-projector library. The DRY motivation is sound for a multi-service ecosystem — good call.


✅ What's Working Well

  • Adapter pattern is clean — the local ScopeProjection interface preserves the existing call signature so callers in workflows.ts and reports.ts need zero changes.
  • Re-exports are thoughtfulSCOPE_TYPES, ScopeStatus, ScopeCharacterization, and ScopeEnv are re-exported so downstream consumers of this module don't break.
  • Line reduction is real — 175 → 59 is a meaningful simplification with no loss of expressiveness at the call sites.

🔴 Blockers

1. file: dependency will break CI/CD

"@chittyos/schema": "file:../../CHITTYFOUNDATION/chittyschema"

This path is machine-local. Any environment where chittyschema isn't at exactly ../../CHITTYFOUNDATION/ relative to this repo — including the GitHub Actions runner, Cloudflare Workers deploy pipeline, and any other developer's machine — will fail at npm install.

Recommended path forward (pick one):

  • Publish @chittyos/schema to npm (private registry or GitHub Packages) and use a semver ref
  • If staying monorepo, use a workspace protocol: "@chittyos/schema": "workspace:*" (requires npm workspaces / pnpm / yarn configured at the monorepo root)
  • At minimum, document the required sibling-repo checkout in the README

This alone is a merge blocker if CI is currently passing only because the runner happens to have the path.


🟡 Issues Worth Addressing

2. tenantId is now in metadata only — verify the shared library stores it

The old implementation explicitly put tenantId in metadata when building the JSONB blob:

const metadata = JSON.stringify({ tenantId: projection.tenantId, ... });

The new adapter does the same via spreading:

metadata: { tenantId: projection.tenantId, ...(projection.metadata ?? {}) }

This is fine if the shared createScopeProjector passes metadata through to the upsert unchanged. But if chittyschema's projector does its own metadata construction or wraps the input, tenantId could be silently dropped. Worth a quick grep of chittyschema's projector source to confirm, and a note in the PR description.

3. waitUntil error suppression may have moved to the library — confirm it's still there

The old scopeLog had an explicit swallow:

try {
  c.executionCtx.waitUntil(promise);
} catch {
  // Test environment / non-Workers runtime — swallow.
}

The new code delegates this to financeProjector. If createScopeProjector doesn't also guard waitUntil in test/non-Workers environments, unit tests that call scopeLog will throw. Verify the shared library handles this.

4. All three test plan items are unchecked

The PR was opened with an incomplete test plan:

  • npm run check passes
  • Scope projection still fires on workflow events
  • No runtime errors in Workers deploy

At minimum, npm run check should be green before this merges (it's a one-liner). The workflow event verification is the critical functional test — a smoke run against a staging Neon database confirming a row appears in public.scopes after triggering a workflow would give confidence here.


🟢 Minor / Nits

5. ScopeProjection interface could lose its field comments

The diff removes the JSDoc comments from each ScopeProjection field. These were the only documentation for what externalId, tenantId, etc. mean. Since callers in this repo use the interface, the comments were useful. Consider keeping them or pointing to the shared library's docs.

6. Default characterization: 'Project' is baked into financeProjector

const financeProjector = createScopeProjector('finance.chitty.cc', {
  characterization: 'Project',
});

This is a reasonable default for finance workflows, but reports.ts also calls scopeLog — reports might warrant 'Session' or another characterization. Worth confirming the default is intentional for all call sites, not just workflows.


Summary

Concept ✅ Correct — shared library is the right approach
File dep path 🔴 Will break CI/CD
Behavioral correctness 🟡 Needs verification on tenantId + waitUntil handling
Tests 🟡 Plan incomplete
Code style ✅ Clean

Fix the file: dependency path and confirm the test plan items before merging. Everything else is advisory.

🤖 Reviewed with Claude Code

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors ChittyFinance’s scope projection logic to delegate workflow→scope upserts to the shared @chittyos/schema/scope-projector, reducing local duplication and centralizing status/type mapping.

Changes:

  • Replaced the inline Neon SQL upsert + status mapping in central-workflows.ts with a thin adapter over createScopeProjector(...).
  • Re-exported shared scope types/constants from @chittyos/schema/scope-projector for downstream usage.
  • Added @chittyos/schema as a dependency via a local file: reference.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
server/lib/central-workflows.ts Swaps in shared scope projector adapter and re-exports shared scope types/constants.
package.json Adds @chittyos/schema dependency for the shared scope projector import.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 41 to +58
export function scopeLog(
c: { executionCtx: { waitUntil(p: Promise<unknown>): void } },
projection: ScopeProjection,
env: ScopeEnv,
): void {
const promise = projectScope(projection, env);
try {
c.executionCtx.waitUntil(promise);
} catch {
// Test environment / non-Workers runtime — swallow.
}
financeProjector(c, env, {
externalId: projection.externalId,
scopeType: projection.scopeType,
characterization: projection.characterization,
title: projection.title,
summary: projection.summary,
localStatus: projection.localStatus,
statusReason: projection.statusReason,
metadata: {
tenantId: projection.tenantId,
...(projection.metadata ?? {}),
},
});
Comment thread package.json
"test:run": "vitest run"
},
"dependencies": {
"@chittyos/schema": "file:../../CHITTYFOUNDATION/chittyschema",
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: e5904b70bb

ℹ️ 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 thread package.json
"test:run": "vitest run"
},
"dependencies": {
"@chittyos/schema": "file:../../CHITTYFOUNDATION/chittyschema",
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 Use a CI-resolvable source for @chittyos/schema

The new dependency points to file:../../CHITTYFOUNDATION/chittyschema, which resolves outside this repository and is not present in a normal checkout, so installs fail unless a separate sibling repo is manually mounted. In this repo’s checked workflow (.github/workflows/security-gates.yml), only this repo is checked out before dependency install, so this change breaks automated installs/build validation in CI and for fresh clones.

Useful? React with 👍 / 👎.

Comment thread package.json
"test:run": "vitest run"
},
"dependencies": {
"@chittyos/schema": "file:../../CHITTYFOUNDATION/chittyschema",
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 Regenerate pnpm lockfile after adding dependency

A direct dependency was added in package.json without updating pnpm-lock.yaml, which causes pnpm install --frozen-lockfile to fail due to lockfile/specifier mismatch. Since the security workflow runs frozen-lockfile installs, this commit will fail dependency audit/build gating until the lockfile is updated in the same change.

Useful? React with 👍 / 👎.

chitcommit added a commit that referenced this pull request Apr 30, 2026
Adds the SERVICE_SCOPE_DB hyperdrive binding (id 89158b50e55a4d5d9279b5d5c890ea7b)
to both root wrangler.jsonc and deploy/system-wrangler.jsonc.

This is the service's own authoritative scopes Hyperdrive, paired with the
existing CHITTYOS_CORE_DB binding for projection into ChittyOS-Core. Required
by chittyschema/identity/scripts/validate-fractal-scopes.ts. The consumer code
already exists in server/lib/central-workflows.ts via the
@chittyos/schema/scope-projector adapter (PR #103) — without this binding the
projector falls back to the SERVICE_SCOPE_DATABASE_URL env var.

Validated: chittyschema validate-fractal-scopes.ts passes against both
wrangler files (exit 0).

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

2 participants