Skip to content

feat(audience): add full audience resource support#730

Merged
meryldakin merged 18 commits intomainfrom
meryldakin/audience-resource
Mar 10, 2026
Merged

feat(audience): add full audience resource support#730
meryldakin merged 18 commits intomainfrom
meryldakin/audience-resource

Conversation

@meryldakin
Copy link
Contributor

@meryldakin meryldakin commented Mar 9, 2026

Summary

Add complete audience resource support to the Knock CLI. Tested locally to validate that all are working as expected.

Commands Implemented

Command Description
audience list List all audiences with pagination
audience get Display a single audience
audience open Open audience in dashboard
audience pull Download from Knock to filesystem
audience push Upload from filesystem to Knock
audience validate Validate local audience files
audience new Scaffold new audience (prompts for static/dynamic type)
audience archive Archive audience (affects ALL environments, requires confirmation)

Copy link
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

meryldakin and others added 2 commits March 9, 2026 11:37
Add complete audience resource implementation following existing patterns:

## Commands
- audience list: List all audiences with pagination
- audience get: Display a single audience
- audience open: Open audience in dashboard
- audience pull: Download from Knock to filesystem
- audience push: Upload from filesystem to Knock
- audience validate: Validate local audience files
- audience new: Scaffold new audience (prompts for static/dynamic type)
- audience archive: Archive audience (affects ALL environments, requires confirmation)

## Infrastructure
- Add AudienceData types with static/dynamic support and segments
- Add API methods: listAudiences, getAudience, upsertAudience, validateAudience, archiveAudience
- Add audience to ResourceType, ALL_RESOURCE_TYPES, and RESOURCE_SUBDIRS
- Add audience directory detection in run-context loader
- Add audience marshal layer (processor, reader, writer, helpers, generator)
- Add viewAudienceUrl helper

## Tests
- Full test coverage for all 8 commands
- Add audience factory for test support

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add listAudiences stub to pull.test.ts and AudienceValidate.validateAll
stub to push.test.ts to fix test failures caused by audience resource
integration.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@meryldakin meryldakin force-pushed the meryldakin/audience-resource branch from f9f4049 to fb5233d Compare March 9, 2026 15:37
@meryldakin meryldakin marked this pull request as ready for review March 9, 2026 15:37
Remove leftover debug logging from the error handler in
writeAudiencesIndexDir to match the pattern used in other
marshal writers (email-layout, workflow).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
meryldakin and others added 2 commits March 9, 2026 11:42
1. Return render() call in list command to properly await pagination
2. Use original dirent.name for filesystem path in pruneAudiencesIndexDir,
   only use lowercased version for key lookup comparison

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Refactor evaluateRecursively to use else-if chain instead of separate
if blocks. This prevents later resource type checks from overwriting
an already-detected resource directory context.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@meryldakin meryldakin marked this pull request as draft March 9, 2026 15:48
When using --push with audience new, now properly forwards the --branch
and --environment flags to AudiencePush.run() so the push targets the
correct branch.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@meryldakin meryldakin marked this pull request as ready for review March 9, 2026 15:49
Remove the development-only restriction from audience push and validate
commands. Unlike some other resources, audiences can be created in any
environment.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
meryldakin and others added 2 commits March 9, 2026 12:38
Remove copied TODO comment that has no associated ticket.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Dynamic audiences should be created with empty segments rather than
example conditions. Users can add their own conditions as needed.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@meryldakin meryldakin requested a review from cjbell March 9, 2026 17:06
meryldakin and others added 2 commits March 9, 2026 13:06
Change readAllForCommandTarget to use ux.error() instead of
throw new Error() to match the pattern used by other resource
readers. This provides clean, formatted CLI error messages instead
of stack traces.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Check isSuccessResp before writing API response to disk. Without this
check, an error response (e.g., 404 not found) would be silently
written to the filesystem as if it were valid audience data.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copy link
Contributor

@cjbell cjbell left a comment

Choose a reason for hiding this comment

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

one thing but we don't need to do it yet

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

@meryldakin meryldakin merged commit 93b1035 into main Mar 10, 2026
9 checks passed
@meryldakin meryldakin deleted the meryldakin/audience-resource branch March 10, 2026 19:20
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