1414
1515### Plugin Data Model
1616- ** Plugin ID
** (e.g.,
` [email protected] ` ): Unique identifier, used as directory name
17- - ** meta.json** : Manual metadata containing ` id ` , ` name ` , ` update_json ` URL , ` description ` , ` homepage ` , ` tags `
17+ - ** meta.json** : Manual metadata containing ` id ` , ` name ` , ` updateUrl ` (or deprecated ` update_json ` ) , ` description ` , ` homepage ` , ` tags ` , optional ` patchedVersions `
1818- ** update.json** : Hosted by plugin developer, follows Zotero extension manifest format with version/compatibility data
1919- ** Tags** : Predefined enum (` metadata ` , ` interface ` , ` attachment ` , ` notes ` , ` reader ` , ` productivity ` , ` visualization ` , ` integration ` , ` ai ` , ` writing ` , ` developer ` , ` favorite ` , ` others ` )
20+ - ** patchedVersions** : Manual version list in meta.json for patching or supplementing remote versions
2021- See [ shared/src/types.ts] ( shared/src/types.ts ) for complete type definitions
2122
2223### Bot Processing Pipeline
23- 1 . ** CLI Entry** ([ bot/src/cli.ts] ( bot/src/cli.ts ) ): Accepts optional plugin ID, defaults to all plugins
24- 2 . ** Process Plugins** ([ bot/src/processor.ts] ( bot/src/processor.ts ) ): Reads ` meta.json ` , fetches remote ` update.json `
25- 3 . ** Parse Versions** : Extracts version data from ` addons[pluginId].updates ` array in update.json
26- 4 . ** Extract Compatibility** : Maps ` applications.zotero ` and ` applications.gecko ` min/max versions
27- 5 . ** Cache** : Stores hash in ` .cache.json ` to detect update.json changes
28- 6 . ** Report** : ([ bot/src/report.ts] ( bot/src/report.ts ) ) Handles GitHub integration and error reporting
29-
30- ### Authentication & External Access
31- - ** GitHub Token** : Required environment variable ` GITHUB_TOKEN ` for API-rate-limited GitHub requests
32- - ** HTTP Fetch** ([ bot/src/utils.ts] ( bot/src/utils.ts ) ):
33- - Detects GitHub URLs and adds Bearer token
34- - Used for fetching remote ` update.json ` files
35- - 10-second timeout for all requests
36- - Axios-based with response type support (json, arraybuffer, etc.)
24+ 1 . ** CLI Entry** ([ bot/src/cli.ts] ( bot/src/cli.ts ) ): ` zbot build ` (default) or ` zbot check ` (PR validation)
25+ 2 . ** Load Meta** ([ bot/src/loaders/meta.ts] ( bot/src/loaders/meta.ts ) ): Validates ` meta.json ` schema and required fields
26+ 3 . ** Fetch Remote** ([ bot/src/loaders/update-json.ts] ( bot/src/loaders/update-json.ts ) ): Fetches remote ` update.json ` and parses ` addons[pluginId].updates ` array
27+ 4 . ** Merge Versions** ([ bot/src/merger.ts] ( bot/src/merger.ts ) ): Combines remote versions with ` patchedVersions ` , prioritizing patches, then sorts semantically
28+ 5 . ** Extract Compatibility** ([ bot/src/merger.ts] ( bot/src/merger.ts ) ): Determines min/max Zotero versions from version list
29+ 6 . ** Generate Outputs** ([ bot/src/processor.ts] ( bot/src/processor.ts ) ): Creates ` meta.generated.json ` and ` latest.json `
30+ 7 . ** Report Results** ([ bot/src/report.ts] ( bot/src/report.ts ) ): Logs to console or GitHub (PR comments, issues)
31+
32+ ### Authentication & HTTP
33+ - ** GitHub Token** : ` GITHUB_TOKEN ` env var for GitHub API rate limits (Bearer auth on GitHub URLs)
34+ - ** HTTP Fetch** ([ bot/src/utils/http.ts] ( bot/src/utils/http.ts ) ): Axios with auto-detection of GitHub domains
35+ - ** Timeout** : 10 seconds for fetch, 30 seconds for XPI download
36+ - ** XPI Handling** ([ bot/src/utils/xpi.ts] ( bot/src/utils/xpi.ts ) ): Download and validate XPI structure (manifest.json)
37+
38+ ## Directory Structure (Bot)
39+
40+ ```
41+ bot/src/
42+ ├── cli.ts # Commander CLI entry point
43+ ├── build.ts # Build orchestration (buildPlugins, checkPlugins)
44+ ├── processor.ts # Single plugin processing pipeline
45+ ├── merger.ts # Version merging and compatibility logic
46+ ├── report.ts # Console/GitHub reporting
47+ ├── github-reporter.ts # Octokit integration for PRs and issues
48+ ├── cache.ts # (stub) Cache management
49+ ├── loaders/
50+ │ ├── index.ts # Re-exports
51+ │ ├── meta.ts # loadPluginMeta() with validation
52+ │ └── update-json.ts # loadUpdateJson() with parsing
53+ └── utils/
54+ ├── index.ts # Re-exports
55+ ├── http.ts # fetchData() with GitHub auth
56+ ├── xpi.ts # downloadXpi, extractXpiInfo, verifyXpi
57+ └── git.ts # detectChangedPlugins() for PR mode
58+ ```
59+
60+ ## Key Interfaces
61+
62+ ** PluginMeta** (from shared): Core metadata with optional ` patchedVersions ` array
63+ ** Version** : ` { version, update_link, update_hash?, strict_min_version?, strict_max_version? } `
64+ ** GeneratedMeta** : Extended PluginMeta with merged versions, compatibility info, and stats
65+ ** ProcessResult** : ` { success: string[], errors: PluginError[] } `
66+ ** PluginError** : ` { pluginId, stage, message } ` where stage is 'schema'|'fetch'|'xpi'|'merge'|'validation'
3767
3868## Developer Workflows
3969
@@ -45,63 +75,89 @@ pnpm install
4575# Process all plugins
4676pnpm run build
4777
48- # Process specific plugin by ID
49- 78+ # Process specific plugin(s)
79+ pnpm run build plugin-id-1 plugin-id-2
80+
81+ # Check mode for PR validation
82+ pnpm run check [changed-plugin-ids]
5083
5184# Generate TypeScript schema from types
5285pnpm run -C shared generate-schema
86+
87+ # Linting
88+ pnpm run lint:fix
5389```
5490
5591### Adding New Plugins
56921 . Create ` plugins/<plugin-id>/ ` directory
57- 2 . Add ` meta.json ` with required fields: ` id ` , ` name ` , ` update_json ` , optionally ` description ` , ` homepage ` , ` tags `
58- 3 . Run bot to generate ` meta.generated.json ` and ` latest.json `
93+ 2 . Add ` meta.json ` with required fields: ` id ` , ` name ` , ` updateUrl ` , plus optionally ` description ` , ` homepage ` , ` tags ` , ` patchedVersions `
94+ 3 . Run ` pnpm run build ` to generate outputs
59954 . Commit and open PR
6096
61- ### Code Quality
62- - ** Linting ** : ` eslint ` with ` @antfu/eslint-config ` , allows ` console ` statements
63- - ** Pre-commit ** : Husky runs ` lint-staged ` on all changed files
64- - Fix linting: ` pnpm run lint:fix `
97+ ### Testing & Validation
98+ - Schema validation is automatic in ` loadPluginMeta() `
99+ - Version compatibility is computed in ` extractCompatibility() `
100+ - XPI verification can be added later (currently a TODO in processor)
65101
66102## Project Conventions
67103
68104### TypeScript Patterns
69105- ** Monorepo imports** : Use workspace protocol, e.g., ` @zotero-plugin-registry/shared `
70- - ** Module system** : ESM (` "type": "module" ` in all package.json files)
106+ - ** Module system** : ESM (` "type": "module" ` in all package.json files), use ` .js ` extensions in imports
71107- ** Async/await** : Standard for all I/O operations
108+ - ** Error handling** : Throw early with descriptive messages, caught and reported in ProcessResult
72109
73110### File Organization
74- - Shared types live in ` shared/src/types.ts ` , exported via package exports in ` shared/package.json `
75- - Schema generation: Run ` scripts/generate-schema.sh ` to create ` meta.schema.json ` from types
76- - Plugin metadata format is validated against ` meta.schema.json `
77-
78- ### Error Handling
79- - ** ProcessResult** : Captures both ` success: string[] ` and ` errors: PluginError[] `
80- - Continues processing remaining plugins even if one fails
81- - Exit code 1 when errors occur (for CI/CD)
82-
83- ## Integration Points
84-
85- ### External Dependencies
86- - ** octokit** : GitHub API client (not actively used in current code but included)
87- - ** axios** : HTTP requests with auth headers
88- - ** adm-zip** : XPI file handling (structure for future use)
89- - ** globby** : File globbing for plugin discovery
90- - ** jsonc** : JSON with comments parsing
91- - ** es-toolkit** : Utility library
92- - ** fs-extra** : File system operations
93-
94- ### CI/CD Considerations
95- - GITHUB_TOKEN must be available in environment for GitHub URL requests
96- - Error reporting to GitHub issues/PRs (via ` report.ts ` , implementation details present)
97- - Build artifacts: ` meta.generated.json ` and ` latest.json ` files per plugin
111+ - Shared types live in [ shared/src/types.ts] ( shared/src/types.ts ) , exported via [ shared/package.json] ( shared/package.json ) exports
112+ - Schema generation: Run ` pnpm run -C shared generate-schema ` to create ` meta.schema.json `
113+ - Bot modules are organized by concern: loaders, utils, core logic
114+
115+ ### Import Ordering (ESLint enforced)
116+ 1 . Node builtins (` node:* ` )
117+ 2 . External packages (alphabetically)
118+ 3 . Type imports
119+ 4 . Local imports (relative paths)
120+
121+ ## Version Merging Strategy
122+
123+ When combining remote and patched versions:
124+ 1 . Build a map indexed by version number
125+ 2 . Add all remote versions first
126+ 3 . Apply patched versions (override if exists, add new if missing)
127+ 4 . Sort by semantic version (descending, using ` semver ` package)
128+ 5 . Return final merged list
129+
130+ This allows teams to patch remote update.json errors without waiting for upstream fixes.
131+
132+ ## External Dependencies
133+
134+ - ** commander** : CLI argument parsing
135+ - ** consola** : Colored console output
136+ - ** axios** : HTTP requests
137+ - ** adm-zip** : XPI (ZIP) file parsing
138+ - ** semver** : Semantic version comparison
139+ - ** simple-git** : Git operations for PR detection
140+ - ** octokit** : GitHub API client
141+ - ** fs-extra** : Enhanced file system
142+ - ** globby** : File pattern matching
143+
144+ ## CI/CD Considerations
145+
146+ - ** GITHUB_TOKEN** must be available for authenticated requests
147+ - ** CI** env var distinguishes CI vs local environments
148+ - ** GITHUB_EVENT_NAME** = 'pull_request' for PR validation
149+ - ** GITHUB_REPOSITORY** = 'owner/repo' for API interactions
150+ - Build fails (exit code 1) if any plugin has errors
151+ - GitHub integration: PR comments on validation failure, issues for scheduled runs
98152
99153## Common Task Patterns
100154
101- ** Adding features to processor** : Modify [ bot/src/processor.ts] ( bot/src/processor.ts ) , ensure ` ProcessResult ` is properly populated with successes/errors
155+ ** Modifying processor logic** : Edit [ bot/src/processor.ts] ( bot/src/processor.ts ) , ensure ProcessResult properly tracks successes/errors
156+
157+ ** Extending metadata support** : Update [ shared/src/types.ts] ( shared/src/types.ts ) interface, then regenerate schema
102158
103- ** Updating shared types ** : Edit [ shared /src/types .ts] ( shared /src/types .ts) , then run schema generation to update validation
159+ ** Adding new loader ** : Create module in ` loaders/ ` , export from [ bot /src/loaders/index .ts] ( bot /src/loaders/index .ts)
104160
105- ** Debugging plugin processing ** : Check ` .cache.json ` in plugin directory to understand last-fetch state; verify ` update_json ` URL format matches Zotero manifest structure
161+ ** GitHub integration ** : Use [ bot/src/github-reporter.ts ] ( bot/src/github-reporter.ts ) for API calls via Octokit
106162
107- ** Working with pnpm ** : Always use workspace commands: ` pnpm run -C <package> ` or ` pnpm run --only <package> ` for scoped tasks
163+ ** Debugging plugin processing ** : Check ` .cache.json ` in plugin directory and verify URL accessibility
0 commit comments