Skip to content

feat(templates): add JSON template import and export capabilities (#10) - #233

Draft
dgomez407 wants to merge 9 commits into
tokyoweb3:mainfrom
dgomez407:feat/import-export-prompt-templates
Draft

feat(templates): add JSON template import and export capabilities (#10)#233
dgomez407 wants to merge 9 commits into
tokyoweb3:mainfrom
dgomez407:feat/import-export-prompt-templates

Conversation

@dgomez407

Copy link
Copy Markdown
Contributor

Summary

Closes #10.

This PR adds support for exporting and importing prompt templates as JSON files in LazyGravity.

Changes

  • Repository Layer (src/database/templateRepository.ts):
    • Added exportTemplates() to export stored prompt templates into formatted JSON matching the specification:
      {
        "version": 1,
        "templates": [
          { "name": "code-review", "prompt": "Review the following code..." }
        ]
      }
    • Added importTemplates(input, mode) with SQLite transaction safety and format validation.
    • Added conflict resolution handling: skip (default) or overwrite.
  • Slash Commands (src/commands/registerSlashCommands.ts & src/commands/slashCommandHandler.ts):
    • Added /template export subcommand to download templates as a .json file attachment.
    • Added /template import subcommand accepting a file attachment and optional conflict (skip | overwrite) mode choice.
  • Discord Bot Integration (src/bot/index.ts):
    • Implemented Discord attachment upload handling, file type & 1MB size checks, and attachment delivery for /template export and /template import.
    • Updated /help output to list export and import subcommands.
  • Documentation & Tests:
    • Updated README.md command reference.
    • Added unit tests in tests/database/templateRepository.test.ts and tests/commands/slashCommandHandler.test.ts.

Verification

Ran full test suite (npm test):

  • All 115 test suites and 1,570 tests passed cleanly.

@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: c78b340d-7e25-4636-a820-7d854158464a

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

@dgomez407
dgomez407 force-pushed the feat/import-export-prompt-templates branch 2 times, most recently from 3590004 to 772e82e Compare August 8, 2026 21:08
…d i18n (tokyoweb3#147)

### Audit Summary Matrix: Issue tokyoweb3#147

| # | Item Description | Initial Audit | Resolution Status | Technical Action Taken |
|---|---|:---:|:---:|---|
| 1 | Type Safety in interactionCreateHandler.ts | Still Present | Fixed & Verified | Removed (interaction as any).channelId and (interaction as any).channel?.threads casts; refactored targetChannel checks to use typed sendableChannel in src/events/interactionCreateHandler.ts. |
| 2 | Dependency Injection (ArtifactService) | Still Present | Fixed & Verified | Replaced new ArtifactService() inline instantiation with deps.artifactService || new ArtifactService() in src/events/interactionCreateHandler.ts. |
| 3 | API Consistency (artifactRenderMode?) | Resolved | Confirmed | Verified UserPreferenceRecord.artifactRenderMode is optional (?) in src/database/userPreferenceRepository.ts. |
| 4 | Encoding Robustness (encodeSelectValue) | Still Present | Fixed & Verified | Replaced numeric filename hash with an 8-character hex SHA-256 hash segment of conversationId + filename in src/services/artifactService.ts. |
| 5 | i18n Integration (artifactsUi.ts) | Still Present | Fixed & Verified | Replaced unlocalized strings with t() i18n helper function across UI elements in src/ui/artifactsUi.ts. |

### Technical Details
- Type Safety: Cleaned up interactionCreateHandler.ts by using typed channel property guards and interaction.channelId directly.
- Dependency Injection: Injected artifactService into interactionCreateHandler for testability and architectural consistency.
- Encoding Robustness: Updated ArtifactService.encodeSelectValue to compute sha256(conversationId + ':' + filename).slice(0, 8).
- Internationalization: Wrapped artifactsUi.ts strings with t() helper function.
- Tests: Added TDD unit assertions in artifactService.test.ts and interactionCreateHandler.test.ts.

Rebased against doc/docstring-cleanup.
Full test suite passing (115 test suites, 1549 tests).
…r precedence, and negative test assertions

### Audit Summary Matrix: Final Review Resolution

| # | Item Description | Initial Audit | Resolution Status | Technical Action Taken |
|---|---|:---:|:---:|---|
| 1 | Type Safety in interactionCreateHandler.ts | Still Present | Fixed & Verified | Created SendableChannel type guard in src/utils/discordChannelUtils.ts; removed inline `{ send: Function }` and `(interaction.channel as any).send` casts across all fallback send paths. |
| 2 | Process Log Buffer Consolidation | Still Present | Fixed & Verified | Exported createDefaultProcessLogBuffer() factory in src/utils/processLogBuffer.ts to centralize log buffer configuration across Discord and Telegram message handlers. |
| 3 | Title Parsing & Separator Precedence | Still Present | Fixed & Verified | Refined parseProjectNameFromTitle in src/services/cdpService.ts with a 3-tier separator hierarchy (Product Suffix > Em/En Dash > Hyphen). |
| 4 | Negative Test Coverage (decodeSelectValue) | Still Present | Fixed & Verified | Added explicit test case for same 8-char short prefix collision rejection in tests/services/artifactService.test.ts. |
| 5 | Regression Test (sendableChannel) | Still Present | Fixed & Verified | Added unit test asserting SendableChannel target channel dispatching in tests/events/interactionCreateHandler.test.ts. |

### Technical Details
- Type Safety: Isolated Discord sendable channel narrowing into src/utils/discordChannelUtils.ts with isSendableChannel predicate.
- Process Log Buffering: Standardized maxChars, maxEntries, and maxEntryLength tuning via createDefaultProcessLogBuffer().
- Title Parsing: Prioritized em-dash (—) and en-dash (–) over plain hyphens (-) when extracting project names from titles.
- Test Coverage: Added SendableChannel dispatching test in interactionCreateHandler.test.ts and prefix collision test in artifactService.test.ts.

Full test suite passing (115 test suites, 1559 tests).
@dgomez407
dgomez407 force-pushed the feat/import-export-prompt-templates branch from 772e82e to 6eb3dec Compare August 10, 2026 11:59
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.

Template import / export

1 participant