nemar-cli 0.3.4-dev.59 → 0.3.4-dev.64

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +120 -10
  2. package/dist/index.js +58 -58
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -10,7 +10,13 @@ Command-line interface for [NEMAR](https://nemar.org) (Neuroelectromagnetic Data
10
10
  ## Features
11
11
 
12
12
  - **Dataset Management**: Upload, download, validate, and version BIDS datasets
13
- - **PR-Based Versioning**: All changes require pull requests (main branch protected)
13
+ - **Resume Uploads**: Failed uploads can be resumed; CLI stores state in `.nemar/config.json`
14
+ - **Smart Authentication**: Verifies GitHub CLI authentication matches NEMAR user
15
+ - **Auto-Accept Invitations**: Automatically accepts GitHub collaboration invitations
16
+ - **IAM Retry Logic**: Handles AWS IAM eventual consistency with automatic retries
17
+ - **Commit Authorship**: Commits attributed to your NEMAR user identity
18
+ - **Private First**: New datasets are private; branch protection applied only on DOI creation
19
+ - **PR-Based Updates**: After DOI, all changes require pull requests
14
20
  - **Collaborative**: Any NEMAR user can contribute to any dataset
15
21
  - **BIDS Validation**: Automatic validation before upload and on PRs
16
22
  - **DOI Integration**: Zenodo DOI creation for dataset versioning
@@ -37,18 +43,25 @@ For dataset operations:
37
43
 
38
44
  - [DataLad](https://www.datalad.org/) and git-annex
39
45
  - [Deno](https://deno.land/) (for BIDS validation)
40
- - GitHub account (for PR collaboration)
46
+ - [GitHub CLI](https://cli.github.com/) (`gh`) - authenticated as your NEMAR user
47
+ - SSH key registered with GitHub
41
48
 
42
49
  ```bash
43
50
  # macOS
44
- brew install datalad git-annex deno
51
+ brew install datalad git-annex deno gh
45
52
 
46
53
  # Ubuntu/Debian
47
54
  sudo apt-get install git-annex
48
55
  pip install datalad
49
56
  curl -fsSL https://deno.land/install.sh | sh
57
+ # Install gh: https://github.com/cli/cli/blob/trunk/docs/install_linux.md
58
+
59
+ # Authenticate GitHub CLI (required for upload)
60
+ gh auth login
50
61
  ```
51
62
 
63
+ **Important:** The GitHub account authenticated with `gh` must match your NEMAR username. The CLI verifies this before upload.
64
+
52
65
  ## Quick Start
53
66
 
54
67
  ```bash
@@ -131,17 +144,42 @@ sequenceDiagram
131
144
 
132
145
  U->>CLI: nemar dataset upload /path
133
146
  CLI->>CLI: Validate BIDS locally
147
+ CLI->>GH: Verify gh CLI authentication
134
148
  CLI->>API: POST /datasets/create
135
149
  API->>API: Assign dataset ID (nm000XXX)
150
+ API->>API: Create IAM credentials
136
151
  API->>GH: Create repo (Admin PAT)
137
152
  API->>GH: Add user as collaborator
138
- API->>GH: Set branch protection
139
153
  API-->>CLI: Dataset ID + presigned URLs
140
- CLI->>S3: Upload data files
154
+ CLI->>GH: Auto-accept invitation (gh API)
155
+ CLI->>CLI: Wait for IAM propagation
156
+ CLI->>S3: Upload data files (with retry)
157
+ CLI->>GH: Commit with user identity
141
158
  CLI->>GH: Push via DataLad
142
159
  CLI-->>U: Success! URLs provided
143
160
  ```
144
161
 
162
+ **Note:** Branch protection is NOT applied during initial upload. Private datasets allow direct pushes to main. Protection is applied when creating a DOI (permanent record).
163
+
164
+ ### Resume Failed Uploads
165
+
166
+ If an upload fails (network issues, S3 errors), you can resume:
167
+
168
+ ```bash
169
+ # Just run upload again - CLI detects existing dataset
170
+ nemar dataset upload /path/to/dataset
171
+ ```
172
+
173
+ The CLI stores dataset metadata in `.nemar/config.json` within your dataset directory. On resume:
174
+ 1. Detects existing dataset ID from local config
175
+ 2. Requests fresh presigned URLs from backend
176
+ 3. Re-uploads files (git-annex handles duplicates)
177
+
178
+ To start fresh (new dataset ID), remove the config:
179
+ ```bash
180
+ rm -rf /path/to/dataset/.nemar
181
+ ```
182
+
145
183
  ### Pull Request Workflow (Contributing to Dataset)
146
184
 
147
185
  ```mermaid
@@ -280,11 +318,13 @@ nemar admin doi create <dataset-id> # Create concept DOI
280
318
 
281
319
  ### Key Principles
282
320
 
283
- 1. **PR-Mandatory**: Main branch is protected; all changes require PRs
284
- 2. **Collaborative**: Any NEMAR user can create PRs on any dataset
285
- 3. **Owner Approval**: Only dataset owner (or admin) can merge PRs
286
- 4. **No Deletion**: Users cannot delete repositories or S3 data
287
- 5. **Audit Trail**: All changes tracked via PR history
321
+ 1. **Private First**: New datasets are private; owners can push directly to main
322
+ 2. **Protection on DOI**: Branch protection applied when creating a DOI (permanent record)
323
+ 3. **PR-Based Updates**: After DOI creation, all changes require pull requests
324
+ 4. **Collaborative**: Any NEMAR user can create PRs on any dataset
325
+ 5. **Owner Approval**: Only dataset owner (or admin) can merge PRs
326
+ 6. **No Deletion**: Users cannot delete repositories or S3 data
327
+ 7. **Audit Trail**: All changes tracked via PR history
288
328
 
289
329
  ## Storage Architecture
290
330
 
@@ -317,6 +357,76 @@ NEMAR_API_URL # Custom API endpoint (default: https://api.nemar.org)
317
357
  NEMAR_NO_COLOR # Disable colored output
318
358
  ```
319
359
 
360
+ ## Troubleshooting
361
+
362
+ ### Upload Issues
363
+
364
+ **"GitHub CLI not authenticated" or "gh CLI username mismatch"**
365
+ ```bash
366
+ # Login to GitHub CLI with your NEMAR account
367
+ gh auth login
368
+ # Verify the authenticated username matches your NEMAR username
369
+ gh auth status
370
+ ```
371
+ The CLI verifies `gh` is authenticated as your NEMAR user to prevent permission issues.
372
+
373
+ **"S3 upload failed" or "AccessDenied (403)"**
374
+ - AWS IAM policy changes take 10-30 seconds to propagate globally
375
+ - The CLI has built-in retry logic (4 retries with progressive delays)
376
+ - If retries fail, wait 30 seconds and run upload again
377
+ - Admin users don't hit this issue (full bucket access)
378
+
379
+ **"Failed to accept GitHub invitation"**
380
+ - The CLI auto-accepts repo invitations, but `gh` must be authenticated as the invited user
381
+ - Manually accept at: https://github.com/nemarDatasets/[dataset-id]/invitations
382
+ - Then re-run the upload command
383
+
384
+ **"Failed to push to GitHub"**
385
+ - Check SSH configuration for multiple GitHub accounts
386
+ - If you have multiple GitHub accounts, configure SSH host aliases:
387
+ ```bash
388
+ # ~/.ssh/config
389
+ Host github-nemar
390
+ HostName github.com
391
+ User git
392
+ IdentityFile ~/.ssh/id_nemar
393
+ ```
394
+ - See `nemar auth status` for SSH setup instructions
395
+
396
+ **"Dataset already exists" / Resume Upload**
397
+ - The CLI stores dataset metadata in `.nemar/config.json`
398
+ - To **resume**: just run `nemar dataset upload` again
399
+ - To **start fresh** with new dataset ID: `rm -rf /path/to/dataset/.nemar`
400
+
401
+ **Upload completes but commits show wrong author**
402
+ - Commits use your NEMAR user identity (username and registered email)
403
+ - Ensure your NEMAR account has correct email registered
404
+ - Check with `nemar auth status`
405
+
406
+ ### Authentication Issues
407
+
408
+ **"API key invalid"**
409
+ ```bash
410
+ nemar auth logout
411
+ nemar auth login
412
+ ```
413
+
414
+ **"Account pending approval"**
415
+ - Admin must approve your account after signup
416
+ - Contact your NEMAR administrator
417
+
418
+ ### Branch Protection
419
+
420
+ **"Cannot push directly to main"**
421
+ - If your dataset has a DOI, branch protection is enabled
422
+ - All changes require pull requests after DOI creation
423
+ - Private datasets without DOI allow direct pushes
424
+
425
+ **"Branch protection not applied after upload"**
426
+ - This is expected for new private datasets
427
+ - Protection is applied when admin creates a DOI (`nemar admin doi create`)
428
+ - Allows owners to freely modify their private workspace
429
+
320
430
  ## Development
321
431
 
322
432
  ```bash