Skip to content

Conversation

@tonyespinoza1
Copy link
Contributor

@tonyespinoza1 tonyespinoza1 commented Nov 24, 2025

Summary

  • Add comprehensive documentation for charm linking in CommonTools patterns
  • Covers source charms (data providers), consumer charms (data receivers), and the linking workflow
  • Includes complete working examples with deployment scripts

Contents

The guide covers:

  1. Source Charm Creation - How to expose data with Output interfaces
  2. Consumer Charm Creation - How to receive linked data with Default<T, null>
  3. Deployment & Linking - CLI commands for ct charm new and ct charm link
  4. Complete Example - Full GPA stats source/reader pattern pair
  5. Quick Reference - Checklists and common type patterns

Test plan

  • Review documentation for accuracy
  • Verify code examples compile correctly
  • Check that CLI command syntax is correct

🤖 Generated with Claude Code


Summary by cubic

Add a Charm Linking Guide to the docs with step-by-step instructions and examples for linking source and consumer charms in CommonTools. Includes Output/Input interface patterns, reactive linking, CLI commands (ct charm new/link), a full GPA stats example with a deployment script, and quick-reference checklists.

Written for commit e4e2709. Summary will update automatically on new commits.

Add comprehensive documentation for charm linking in CommonTools patterns,
covering how to create source charms that expose data, consumer charms that
receive linked data, and the CLI commands for deploying and linking charms.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Update browser access URLs to use port 8000 instead of 5173,
reflecting the upcoming convention change.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
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.

2 issues found across 1 file

Prompt for AI agents (all 2 issues)

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


<file name="docs/common/CHARM_LINKING.md">

<violation number="1" location="docs/common/CHARM_LINKING.md:61">
The source-charm example calls a `percentile` helper that is never defined, so the sample code cannot compile or run as written.</violation>

<violation number="2" location="docs/common/CHARM_LINKING.md:73">
The guide’s source-charm recipe invokes `parseData(rawData)` without ever defining that helper, so the example cannot be executed as provided.</violation>
</file>

Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR

"Stats Calculator",
({ name, rawData }) => {
// Compute derived values
const parsedValues = parseData(rawData);
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Nov 24, 2025

Choose a reason for hiding this comment

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

The guide’s source-charm recipe invokes parseData(rawData) without ever defining that helper, so the example cannot be executed as provided.

Prompt for AI agents
Address the following comment on docs/common/CHARM_LINKING.md at line 73:

<comment>The guide’s source-charm recipe invokes `parseData(rawData)` without ever defining that helper, so the example cannot be executed as provided.</comment>

<file context>
@@ -0,0 +1,447 @@
+  &quot;Stats Calculator&quot;,
+  ({ name, rawData }) =&gt; {
+    // Compute derived values
+    const parsedValues = parseData(rawData);
+    const computedStats = calculateStats(parsedValues);
+
</file context>

✅ Addressed in 94cdcac

const average = sum / n;

// Quartile calculations...
const q1 = percentile(sorted, 25);
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Nov 24, 2025

Choose a reason for hiding this comment

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

The source-charm example calls a percentile helper that is never defined, so the sample code cannot compile or run as written.

Prompt for AI agents
Address the following comment on docs/common/CHARM_LINKING.md at line 61:

<comment>The source-charm example calls a `percentile` helper that is never defined, so the sample code cannot compile or run as written.</comment>

<file context>
@@ -0,0 +1,447 @@
+  const average = sum / n;
+
+  // Quartile calculations...
+  const q1 = percentile(sorted, 25);
+  const median = percentile(sorted, 50);
+  const q3 = percentile(sorted, 75);
</file context>

✅ Addressed in 94cdcac

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.

2 issues found across 1 file

Prompt for AI agents (all 2 issues)

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


<file name="docs/common/CHARM_LINKING.md">

<violation number="1" location="docs/common/CHARM_LINKING.md:61">
The documentation references an undefined `percentile` helper in the source-charm example, making the sample code invalid.</violation>

<violation number="2" location="docs/common/CHARM_LINKING.md:73">
The Stats source-charm example calls `parseData` without providing an implementation, so the documented code cannot compile as written.</violation>
</file>

Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR

const average = sum / n;

// Quartile calculations...
const q1 = percentile(sorted, 25);
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Nov 24, 2025

Choose a reason for hiding this comment

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

The documentation references an undefined percentile helper in the source-charm example, making the sample code invalid.

Prompt for AI agents
Address the following comment on docs/common/CHARM_LINKING.md at line 61:

<comment>The documentation references an undefined `percentile` helper in the source-charm example, making the sample code invalid.</comment>

<file context>
@@ -0,0 +1,447 @@
+  const average = sum / n;
+
+  // Quartile calculations...
+  const q1 = percentile(sorted, 25);
+  const median = percentile(sorted, 50);
+  const q3 = percentile(sorted, 75);
</file context>

✅ Addressed in 94cdcac

"Stats Calculator",
({ name, rawData }) => {
// Compute derived values
const parsedValues = parseData(rawData);
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Nov 24, 2025

Choose a reason for hiding this comment

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

The Stats source-charm example calls parseData without providing an implementation, so the documented code cannot compile as written.

Prompt for AI agents
Address the following comment on docs/common/CHARM_LINKING.md at line 73:

<comment>The Stats source-charm example calls `parseData` without providing an implementation, so the documented code cannot compile as written.</comment>

<file context>
@@ -0,0 +1,447 @@
+  &quot;Stats Calculator&quot;,
+  ({ name, rawData }) =&gt; {
+    // Compute derived values
+    const parsedValues = parseData(rawData);
+    const computedStats = calculateStats(parsedValues);
+
</file context>

✅ Addressed in 94cdcac

return { average, q1, median, q3, iqr, count: n };
});

export default recipe<Input, Output>(
Copy link
Contributor

Choose a reason for hiding this comment

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

let's switch to pattern, which also means leaving out the title in the next line.

You can add the title back in the input schema via jsdoc: Write /** Stats Calculator */ right above defining the Input type.

export default recipe<Input, Input>(
"Stats Reader",
({ name, linkedStats }) => {
const dataPresent = hasData(linkedStats);
Copy link
Contributor

Choose a reason for hiding this comment

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

this is unused and honestly also a distraction, i'd remove this here and above

```typescript
// Helper functions handle null gracefully
const hasData = lift((s: Stats | null) => s !== null);
const getAverage = lift((s: Stats | null) => s?.average);
Copy link
Contributor

Choose a reason for hiding this comment

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

getAverage that just reads a property is not necessary, you can just write formatNumber(linkedStats.average) below in the JSX


1. **Use `Default<T, null>` for linked fields** - provides fallback when unlinked
2. **Interface must match source** - the Stats interface must be identical
3. **Use `lift()` for null-safe access** - `lift((s) => s?.field)` handles null gracefully
Copy link
Contributor

Choose a reason for hiding this comment

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

remove this third point.

1. **Use `Default<T, null>` for linked fields** - provides fallback when unlinked
2. **Interface must match source** - the Stats interface must be identical
3. **Use `lift()` for null-safe access** - `lift((s) => s?.field)` handles null gracefully
4. **Show helpful UI when unlinked** - guide users on how to link
Copy link
Contributor

Choose a reason for hiding this comment

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

do we want that guidance? seems misplaced to me...

Copy link
Contributor

@seefeldb seefeldb left a comment

Choose a reason for hiding this comment

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

some minor suggestions

- Change `recipe` to `pattern` throughout all examples
- Add JSDoc comments above Input interfaces for charm titles
- Add missing `parseData` lifted function implementation
- Inline `percentile` helper inside `calculateStats` function
- Update Quick Reference checklist to mention `pattern` and JSDoc

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Remove third point about lift() for null-safe access from Key Rules
- Remove fourth point about showing helpful UI when unlinked
- Remove unused hasData and getAverage helpers from consumer example
- Simplify consumer example to use linkedStats?.average directly
- Add note about importing Stats type from source charm
- Update Consumer Charm Checklist to be more concise

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@tonyespinoza1 tonyespinoza1 merged commit c0fcf80 into main Nov 24, 2025
10 checks passed
@tonyespinoza1 tonyespinoza1 deleted the docs/charm-linking-guide branch November 24, 2025 23:41
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