Skip to content

Conversation

@seefeldb
Copy link
Contributor

@seefeldb seefeldb commented Sep 24, 2025

refactor(charm): remove built-in Charm schema; require explicit schemas

Removes default loading of [UI] and in many cases of everything else!

  • Replace Charm type and charmSchema with schema-driven access.
  • CharmManager.get now accepts optional schema and returns typed cells.
  • Export nameSchema and uiSchema; update callers to read NAME and UI via schema.
  • Introduce generic CharmController and CharmsController.
  • Background worker: access bgUpdater as Stream via schema; map typed.
  • Runner: handle Stream in Cellify for asSchema.
  • CLI, UI, and tests: replace Cell with Cell; pass schemas or cast.
  • Persistent flows return typed cells using recipe.resultSchema.
  • search.ts and format.ts use nameSchema for NAME access.
  • AppView reads title via cc().get(id, nameSchema) and cell.key(NAME).

Motivation:

  • Decouple CharmManager from a fixed schema; allow arbitrary charm shapes.
  • Make invalid states unrepresentable by requiring explicit schemas at access.
  • Enable streams to be typed via schema (asStream) consistently.

Summary by cubic

Refactored charm APIs to remove the built-in Charm schema and require explicit schemas, enabling typed access and decoupling charm shape across Runner, CLI, and UI.

  • Refactors

    • CharmManager.get now accepts an optional schema and returns typed cells; persistent runs use recipe.resultSchema.
    • Exported nameSchema and uiSchema; callers read NAME and UI via schema.
    • Introduced generic CharmController and CharmsController.
    • Background worker reads bgUpdater as Stream via schema.
    • Runner: Cellify supports Stream; isStream added.
    • CLI/UI/tests replaced Cell with Cell or typed via schema (e.g., vdomSchema for UI).
    • search.ts and format.ts use nameSchema for names; AppView gets active charm via cc().get(id, nameSchema).
  • Migration

    • Pass a schema when calling CharmManager.get or CharmsController.get; use nameSchema/uiSchema for NAME/UI.
    • Wrap cells with asSchema(...) before accessing typed fields or streams (use asStream in the schema).
    • Replace Cell with Cell or Cell<Schema<...>>; prefer recipe.resultSchema for persistent results.
    • Update handlers to read streams via schema and isStream.
    • Provide explicit array/object schemas in UI components that consume charm collections (temporary any used in ct-kanban).

- Replace Charm type and charmSchema with schema-driven access.
- CharmManager.get now accepts optional schema and returns typed cells.
- Export nameSchema and uiSchema; update callers to read NAME and UI via schema.
- Introduce generic CharmController<T> and CharmsController<T>.
- Background worker: access bgUpdater as Stream via schema; map typed.
- Runner: handle Stream in Cellify<T> for asSchema.
- CLI, UI, and tests: replace Cell<Charm> with Cell<unknown>; pass schemas or cast.
- Persistent flows return typed cells using recipe.resultSchema.
- search.ts and format.ts use nameSchema for NAME access.
- AppView reads title via cc().get(id, nameSchema) and cell.key(NAME).

Motivation:
- Decouple CharmManager from a fixed schema; allow arbitrary charm shapes.
- Make invalid states unrepresentable by requiring explicit schemas at access.
- Enable streams to be typed via schema (asStream) consistently.
@seefeldb seefeldb force-pushed the chore/remove-charm-manager-schema-assumption branch from cf2ba83 to 44bf3cb Compare September 24, 2025 18:55
Copy link
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

This PR refactors the Charm system to remove the built-in Charm type and schema, requiring explicit schemas for all charm access operations. This decouples CharmManager from a fixed schema and makes invalid states unrepresentable by requiring explicit schemas at access time.

  • Replace the global Charm type and charmSchema with schema-driven access patterns
  • Update CharmManager.get() to accept optional schemas and return typed cells
  • Export separate nameSchema and uiSchema for specific access patterns

Reviewed Changes

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

Show a summary per file
File Description
packages/ui/src/v2/components/ct-outliner/types.ts Replace Charm type with unknown for MentionableItem and Attachment
packages/ui/src/v2/components/ct-outliner/ct-outliner.ts Update component to use unknown instead of Charm, add type assertions
packages/ui/src/v2/components/ct-kanban/ct-kanban.ts Replace Charm type references with any/unknown types
packages/ui/src/v2/components/ct-code-editor/ct-code-editor.ts Add local schema definitions and update mentionable handling
packages/shell/src/views/AppView.ts Update to use nameSchema for charm title access
packages/shell/integration/iframe-counter-charm.test.ts Replace Charm type with specific typed interface
packages/runner/src/cell.ts Add Stream support to Cellify type helper
packages/runner/integration/array_push.test.ts Update charm access to use explicit schema
packages/cli/lib/charm.ts Remove Charm type, update function signatures to use unknown
packages/cli/lib/charm-render.ts Add explicit UI schema for charm rendering
packages/cli/commands/charm.ts Update UI symbol access pattern
packages/charm/src/workflow.ts Replace Charm type with unknown throughout workflow system
packages/charm/src/search.ts Update search to use nameSchema for charm name access
packages/charm/src/ops/charms-controller.ts Add generic type parameter and schema support
packages/charm/src/ops/charm-controller.ts Update to support generic types and use nameSchema
packages/charm/src/manager.ts Replace charmSchema with separate nameSchema and uiSchema exports
packages/charm/src/iterate.ts Remove Charm type dependencies
packages/charm/src/index.ts Update exports to remove charmSchema, add nameSchema and uiSchema
packages/charm/src/imagine.ts Replace Charm type with unknown
packages/charm/src/iframe/recipe.ts Update function signature to use unknown
packages/charm/src/format.ts Update to use nameSchema instead of charmSchema
packages/charm/src/commands.ts Update function signatures and schema usage
packages/background-charm-service/src/worker.ts Add explicit schema for bgUpdater stream access

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

5 issues found across 23 files

Prompt for AI agents (all 5 issues)

Understand the root cause of the following 5 issues and fix them.


<file name="packages/charm/src/workflow.ts">

<violation number="1" location="packages/charm/src/workflow.ts:1071">
Guard charmData with an object check before using the &quot;in&quot; operator to avoid runtime TypeError.</violation>
</file>

<file name="packages/cli/commands/charm.ts">

<violation number="1" location="packages/cli/commands/charm.ts:29">
Import uses the &quot;commontools&quot; alias not present in packages/cli/deno.json, breaking local CLI runs; use a relative path or add the alias.</violation>
</file>

<file name="packages/runner/src/cell.ts">

<violation number="1" location="packages/runner/src/cell.ts:285">
Cellify now allows Streams, but normalizeAndDiff/diffAndUpdate do not convert Stream instances to links. RegularCell.set/update/push will recurse into Stream internals and attempt non-JSON writes, causing errors or corrupt data.</violation>
</file>

<file name="packages/ui/src/v2/components/ct-outliner/ct-outliner.ts">

<violation number="1" location="packages/ui/src/v2/components/ct-outliner/ct-outliner.ts:1608">
Escape mention name when constructing the markdown link to prevent markdown/HTML injection and formatting issues in rendered content.</violation>
</file>

<file name="packages/ui/src/v2/components/ct-code-editor/ct-code-editor.ts">

<violation number="1" location="packages/ui/src/v2/components/ct-code-editor/ct-code-editor.ts:832">
ID comparison uses getEntityId on raw objects, producing empty curIds and preventing $mentioned updates.</violation>
</file>

React with 👍 or 👎 to teach cubic. Mention @cubic-dev-ai to give feedback, ask questions, or re-run the review.

Copy link
Contributor

@bfollington bfollington left a comment

Choose a reason for hiding this comment

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

LGTM!

@bfollington bfollington merged commit b90adf0 into main Sep 24, 2025
7 checks passed
@bfollington bfollington deleted the chore/remove-charm-manager-schema-assumption branch September 24, 2025 23:56
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.

3 participants