@refhub/cli 1.6.0 → 1.8.0

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.
package/README.md CHANGED
@@ -92,8 +92,8 @@ refhub vaults shares remove <vaultId> <shareId>
92
92
  ```bash
93
93
  refhub items list --vault <id> [--page] [--limit]
94
94
  refhub items get --vault <id> <itemId>
95
- refhub items add --vault <id> --title <t> [--authors "Smith J,Doe A"] [--year] [--doi] [--url] [--pdf-url] [--tags <id,id>] [--notes]
96
- refhub items update --vault <id> <itemId> [--title] [--authors] [--year] [--doi] [--url] [--pdf-url] [--tags <id,id>] [--notes]
95
+ refhub items add --vault <id> --title <t> [--author "Smith, John" ...] [--authors "Smith, John; Doe, Jane"] [--year] [--doi] [--url] [--pdf-url] [--tags <id,id>] [--notes]
96
+ refhub items update --vault <id> <itemId> [--title] [--author ... | --authors] [--year] [--doi] [--url] [--pdf-url] [--tags <id,id>] [--notes] [--section <sectionId> | --unset-section] [--featured | --unfeature] [--featured-note <text>]
97
97
  refhub items delete --vault <id> <itemId> --confirm
98
98
  refhub items upsert --vault <id> --file <items.json> [--idempotency-key]
99
99
  refhub items preview --vault <id> --file <items.json>
@@ -106,6 +106,25 @@ refhub items changes --vault <id> --since <ISO>
106
106
 
107
107
  `--pdf-url` sets the frontend's `publisher_pdf` field (a link to a publisher-hosted PDF). it is distinct from the frontend's `drive_pdf` field (the Google Drive-hosted copy created by `refhub pdf upload`, see below) — the Drive copy is readable back afterward too, as `drive_pdf_url` on item reads (see the `pdf` command below).
108
108
 
109
+ authors: repeat `--author` once per author (commas are kept, so `--author "Smith, John"` is one author), or pass them all to `--authors` separated by `;`. Without a `;`, `--authors` still splits on commas, as before, and prints a hint.
110
+
111
+ empty values: on `items update`, an empty value clears that field (`--doi ""`, `--year ""`, `--authors ""`, `--tags ""` and so on); `--title` can't be empty. On `items add`, an empty optional value is simply left out.
112
+
113
+ `--section`/`--unset-section`/`--featured`/`--unfeature`/`--featured-note` are vault-local curation fields — grouping and highlighting items for display on public vault pages. **Setting any of them requires vault owner access**, even for an api key with `vaults:write` scope held by a non-owner editor share — the backend runs a second, owner-level access check for these specific fields, separate from the editor-level check for everything else `items update` can change.
114
+
115
+ ### sections
116
+
117
+ Curated sections group a vault's items for display on public vault pages. Listing needs only viewer access; create/update/delete require **owner** access (`vaults:admin` scope, and the caller must own the vault — an editor share cannot manage sections even with `vaults:admin`).
118
+
119
+ ```bash
120
+ refhub sections list --vault <id>
121
+ refhub sections create --vault <id> --name <n> [--description] [--position]
122
+ refhub sections update --vault <id> <sectionId> [--name] [--description] [--position]
123
+ refhub sections delete --vault <id> <sectionId>
124
+ ```
125
+
126
+ deleting a section unfiles its items (`section_id` is cleared) rather than deleting them.
127
+
109
128
  ### tags
110
129
 
111
130
  ```bash
@@ -126,6 +145,39 @@ refhub relations update --vault <id> <relationId> --type <...>
126
145
  refhub relations delete --vault <id> <relationId>
127
146
  ```
128
147
 
148
+ `refhub relations scan` is client-side orchestration on top of the existing `discover`/manual-relation building blocks — there is no dedicated backend route for it, same as `enrich`. For each vault item with a DOI, it looks up the item's Semantic Scholar paper id, fetches its references and citations, and matches each returned paper against sibling items already in the same vault (DOI match first, falling back to an exact, case-insensitive title match), mirroring the RefHub frontend's own relationship-suggestion matching. Every match becomes a `cites` relation — item → reference for references, matched-paper → item for citations — skipping any pair that already has a relation between them.
149
+
150
+ ```bash
151
+ refhub relations scan --vault <id> [--item <itemId>] [--dry-run] [--limit <n>]
152
+ ```
153
+
154
+ - omit `--item` to scan every item in the vault that has a DOI
155
+ - `--dry-run` reports what would be created without writing anything
156
+ - `--limit` caps references/citations fetched per item from Semantic Scholar (1–25, same as `discover references`/`discover citations`)
157
+ - rate-limited client-side to roughly 1 item/s (each item makes 3 Semantic Scholar requests); backend cache/rate-limit/stale fallback also applies
158
+ - only ever proposes `relation_type: "cites"` — there's no basis in citation-graph data alone for `extends`/`contradicts`/etc., those remain manual via `relations create`/`update`
159
+
160
+ ### inbox
161
+
162
+ capture papers now, file them into a vault later. unlike every other command group, inbox items have no `--vault` — they belong to the account until `accept` files one.
163
+
164
+ ```bash
165
+ refhub inbox list [--page <n>] [--limit <n>]
166
+ refhub inbox capture doi <doi>
167
+ refhub inbox capture bibtex (--bibtex <string> | --file <path>) # bulk -- one inbox item per entry
168
+ refhub inbox capture manual --title <title>
169
+ refhub inbox accept <itemId> --vault <id> [--tags <id,id>]
170
+ refhub inbox reject <itemId> --confirm
171
+ refhub inbox merge <itemId> --confirm
172
+ refhub inbox postpone <itemId>
173
+ refhub inbox delete <itemId> --confirm
174
+ ```
175
+
176
+ - `list` is paginated server-side (default 50 per page, max 200) — pass `--page`/`--limit` to see more than the first page.
177
+ - `merge` files the item as a duplicate of whatever match the backend already found for it (`duplicate_of_publication_id`) — it does not accept a `--vault`/target of your own choosing.
178
+ - `reject`/`merge`/`delete` require `--confirm`: none of the three can be undone. `accept` and `postpone` don't need it — accept files real data rather than discarding it, and postpone only reorders the queue.
179
+ - `capture bibtex` inserts entries one at a time server-side with no idempotency key — if one entry fails partway through a large batch, earlier entries in that batch are already created. Check `inbox list` before retrying the same content to avoid duplicates (tracked for a real fix as `.netlify#40`).
180
+
129
181
  ### import
130
182
 
131
183
  ```bash
@@ -224,6 +276,7 @@ rate-limited responses (429) include `retry_after_seconds`.
224
276
 
225
277
  - `vaults delete` and `items delete` require `--confirm` — hard deletes, no undo
226
278
  - `vaults archive` requires `--confirm` — permanent read-only lockdown, no undo, no unarchive command exists
279
+ - `inbox reject`, `inbox merge`, and `inbox delete` require `--confirm` — none of the three can be undone
227
280
  - `items upsert` without `--idempotency-key` emits a `partial_write_risk` warning before exiting 1 on failure
228
281
  - `items update --tags` warns that the tags list is a full replacement
229
282
 
package/dist/client.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ApiResponse, Vault, VaultDetail, Share, Item, UpsertResult, PreviewResult, Tag, Relation, BibTeXImportResult, AuditEntry, VaultStats, RelationType, SemanticScholarPaper, SemanticScholarDoiMetadata } from './types.js';
1
+ import type { ApiResponse, Vault, VaultDetail, Share, Item, UpsertResult, PreviewResult, Tag, Relation, BibTeXImportResult, AuditEntry, VaultStats, RelationType, SemanticScholarPaper, SemanticScholarDoiMetadata, Section, InboxItem } from './types.js';
2
2
  export declare class RefHubError extends Error {
3
3
  readonly code: string;
4
4
  readonly request_id: string;
@@ -74,6 +74,10 @@ export declare class RefHubClient {
74
74
  tag_ids?: string[];
75
75
  notes?: string;
76
76
  pdf_url?: string;
77
+ section_id?: string | null;
78
+ section_position?: number;
79
+ featured?: boolean;
80
+ featured_note?: string | null;
77
81
  }): Promise<ApiResponse<Item>>;
78
82
  deleteItem(vaultId: string, itemId: string): Promise<ApiResponse<{
79
83
  id: string;
@@ -113,6 +117,20 @@ export declare class RefHubClient {
113
117
  item_id: string;
114
118
  tag_ids: string[];
115
119
  }>>;
120
+ listSections(vaultId: string): Promise<ApiResponse<Section[]>>;
121
+ createSection(vaultId: string, body: {
122
+ name: string;
123
+ description?: string;
124
+ position?: number;
125
+ }): Promise<ApiResponse<Section>>;
126
+ updateSection(vaultId: string, sectionId: string, body: {
127
+ name?: string;
128
+ description?: string;
129
+ position?: number;
130
+ }): Promise<ApiResponse<Section>>;
131
+ deleteSection(vaultId: string, sectionId: string): Promise<ApiResponse<{
132
+ id: string;
133
+ }>>;
116
134
  listRelations(vaultId: string, type?: string): Promise<ApiResponse<Relation[]>>;
117
135
  createRelation(vaultId: string, body: {
118
136
  publication_id: string;
@@ -125,6 +143,31 @@ export declare class RefHubClient {
125
143
  deleteRelation(vaultId: string, relationId: string): Promise<ApiResponse<{
126
144
  id: string;
127
145
  }>>;
146
+ listInbox(params?: {
147
+ page?: number;
148
+ limit?: number;
149
+ }): Promise<ApiResponse<InboxItem[]>>;
150
+ captureInboxDoi(doi: string): Promise<ApiResponse<InboxItem>>;
151
+ captureInboxBibtex(bibtex: string): Promise<ApiResponse<InboxItem[]>>;
152
+ captureInboxManual(title: string): Promise<ApiResponse<InboxItem>>;
153
+ acceptInboxItem(itemId: string, vaultId: string, tagIds?: string[]): Promise<ApiResponse<{
154
+ vault_publication_id: string;
155
+ publication_id: string;
156
+ }>>;
157
+ rejectInboxItem(itemId: string): Promise<ApiResponse<{
158
+ id: string;
159
+ }>>;
160
+ mergeInboxItem(itemId: string): Promise<ApiResponse<{
161
+ id: string;
162
+ filed_publication_id: string;
163
+ }>>;
164
+ postponeInboxItem(itemId: string): Promise<ApiResponse<{
165
+ id: string;
166
+ sort_order: number;
167
+ }>>;
168
+ deleteInboxItem(itemId: string): Promise<ApiResponse<{
169
+ id: string;
170
+ }>>;
128
171
  importDoi(vaultId: string, doi: string, tagIds?: string[]): Promise<ApiResponse<{
129
172
  item: Item;
130
173
  }>>;
package/dist/client.js CHANGED
@@ -155,6 +155,19 @@ export class RefHubClient {
155
155
  detachTags(vaultId, itemId, tagIds) {
156
156
  return this.req('POST', `/vaults/${vaultId}/tags/detach`, { item_id: itemId, tag_ids: tagIds });
157
157
  }
158
+ // ── Sections ─────────────────────────────────────────────────────────────────
159
+ listSections(vaultId) {
160
+ return this.req('GET', `/vaults/${vaultId}/sections`);
161
+ }
162
+ createSection(vaultId, body) {
163
+ return this.req('POST', `/vaults/${vaultId}/sections`, body);
164
+ }
165
+ updateSection(vaultId, sectionId, body) {
166
+ return this.req('PATCH', `/vaults/${vaultId}/sections/${sectionId}`, body);
167
+ }
168
+ deleteSection(vaultId, sectionId) {
169
+ return this.req('DELETE', `/vaults/${vaultId}/sections/${sectionId}`);
170
+ }
158
171
  // ── Relations ────────────────────────────────────────────────────────────────
159
172
  listRelations(vaultId, type) {
160
173
  const qs = type ? `?type=${encodeURIComponent(type)}` : '';
@@ -169,6 +182,42 @@ export class RefHubClient {
169
182
  deleteRelation(vaultId, relationId) {
170
183
  return this.req('DELETE', `/vaults/${vaultId}/relations/${relationId}`);
171
184
  }
185
+ // ── Inbox ────────────────────────────────────────────────────────────────────
186
+ // Account-scoped, not vault-scoped -- an inbox item has no vault until accept()
187
+ // files it into one, unlike every other resource above.
188
+ listInbox(params = {}) {
189
+ const q = new URLSearchParams();
190
+ if (params.page !== undefined)
191
+ q.set('page', String(params.page));
192
+ if (params.limit !== undefined)
193
+ q.set('limit', String(params.limit));
194
+ const qs = q.toString() ? `?${q}` : '';
195
+ return this.req('GET', `/inbox${qs}`);
196
+ }
197
+ captureInboxDoi(doi) {
198
+ return this.req('POST', '/inbox', { source_type: 'doi', source_ref: doi });
199
+ }
200
+ captureInboxBibtex(bibtex) {
201
+ return this.req('POST', '/inbox', { source_type: 'bibtex', source_ref: bibtex });
202
+ }
203
+ captureInboxManual(title) {
204
+ return this.req('POST', '/inbox', { source_type: 'manual', parsed_fields: { title } });
205
+ }
206
+ acceptInboxItem(itemId, vaultId, tagIds = []) {
207
+ return this.req('POST', `/inbox/${itemId}/accept`, { vault_id: vaultId, tag_ids: tagIds });
208
+ }
209
+ rejectInboxItem(itemId) {
210
+ return this.req('POST', `/inbox/${itemId}/reject`);
211
+ }
212
+ mergeInboxItem(itemId) {
213
+ return this.req('POST', `/inbox/${itemId}/merge`);
214
+ }
215
+ postponeInboxItem(itemId) {
216
+ return this.req('POST', `/inbox/${itemId}/postpone`);
217
+ }
218
+ deleteInboxItem(itemId) {
219
+ return this.req('DELETE', `/inbox/${itemId}`);
220
+ }
172
221
  // ── Import ───────────────────────────────────────────────────────────────────
173
222
  importDoi(vaultId, doi, tagIds = []) {
174
223
  return this.req('POST', `/vaults/${vaultId}/import/doi`, { doi, tag_ids: tagIds });
@@ -0,0 +1,15 @@
1
+ import type { Command } from 'commander';
2
+ import { RefHubClient } from '../client.js';
3
+ export declare function handleInboxList(client: RefHubClient, opts: {
4
+ page?: number;
5
+ limit?: number;
6
+ }, tableMode: boolean): Promise<void>;
7
+ export declare function handleInboxCaptureDoi(client: RefHubClient, doi: string, tableMode: boolean): Promise<void>;
8
+ export declare function handleInboxCaptureBibtex(client: RefHubClient, bibtex: string, tableMode: boolean): Promise<void>;
9
+ export declare function handleInboxCaptureManual(client: RefHubClient, title: string, tableMode: boolean): Promise<void>;
10
+ export declare function handleInboxAccept(client: RefHubClient, itemId: string, vaultId: string, tagsCsv: string | undefined, tableMode: boolean): Promise<void>;
11
+ export declare function handleInboxReject(client: RefHubClient, itemId: string, confirmed: boolean): Promise<void>;
12
+ export declare function handleInboxMerge(client: RefHubClient, itemId: string, confirmed: boolean, tableMode: boolean): Promise<void>;
13
+ export declare function handleInboxPostpone(client: RefHubClient, itemId: string, tableMode: boolean): Promise<void>;
14
+ export declare function handleInboxDelete(client: RefHubClient, itemId: string, confirmed: boolean): Promise<void>;
15
+ export declare function registerInbox(program: Command): void;
@@ -0,0 +1,159 @@
1
+ // src/commands/inbox.ts
2
+ import { readFileSync } from 'fs';
3
+ import { resolveClient, run } from '../client.js';
4
+ import { format } from '../format.js';
5
+ export async function handleInboxList(client, opts, tableMode) {
6
+ const result = await client.listInbox(opts);
7
+ format(result, tableMode, ['id', 'status', 'source_type', 'source_ref', 'suggested_vault_id', 'created_at']);
8
+ }
9
+ export async function handleInboxCaptureDoi(client, doi, tableMode) {
10
+ const result = await client.captureInboxDoi(doi);
11
+ format(result, tableMode);
12
+ }
13
+ export async function handleInboxCaptureBibtex(client, bibtex, tableMode) {
14
+ const result = await client.captureInboxBibtex(bibtex);
15
+ format(result, tableMode);
16
+ }
17
+ export async function handleInboxCaptureManual(client, title, tableMode) {
18
+ const result = await client.captureInboxManual(title);
19
+ format(result, tableMode);
20
+ }
21
+ export async function handleInboxAccept(client, itemId, vaultId, tagsCsv, tableMode) {
22
+ const tagIds = tagsCsv ? tagsCsv.split(',').map((t) => t.trim()) : [];
23
+ const result = await client.acceptInboxItem(itemId, vaultId, tagIds);
24
+ format(result, tableMode);
25
+ }
26
+ export async function handleInboxReject(client, itemId, confirmed) {
27
+ if (!confirmed) {
28
+ process.stderr.write(JSON.stringify({ error: { code: 'confirm_required', message: 'Pass --confirm to acknowledge there is no way to un-reject an inbox item.' } }) + '\n');
29
+ process.exit(2);
30
+ }
31
+ const result = await client.rejectInboxItem(itemId);
32
+ format(result, false);
33
+ }
34
+ export async function handleInboxMerge(client, itemId, confirmed, tableMode) {
35
+ if (!confirmed) {
36
+ process.stderr.write(JSON.stringify({ error: { code: 'confirm_required', message: 'Pass --confirm to acknowledge there is no way to un-merge an inbox item.' } }) + '\n');
37
+ process.exit(2);
38
+ }
39
+ const result = await client.mergeInboxItem(itemId);
40
+ format(result, tableMode);
41
+ }
42
+ export async function handleInboxPostpone(client, itemId, tableMode) {
43
+ const result = await client.postponeInboxItem(itemId);
44
+ format(result, tableMode);
45
+ }
46
+ export async function handleInboxDelete(client, itemId, confirmed) {
47
+ if (!confirmed) {
48
+ process.stderr.write(JSON.stringify({ error: { code: 'confirm_required', message: 'Pass --confirm to acknowledge this is a hard delete with no undo.' } }) + '\n');
49
+ process.exit(2);
50
+ }
51
+ const result = await client.deleteInboxItem(itemId);
52
+ format(result, false);
53
+ }
54
+ export function registerInbox(program) {
55
+ const inbox = program.command('inbox').description('Capture and triage papers before filing them into a vault');
56
+ inbox
57
+ .command('list')
58
+ .description('List pending inbox items')
59
+ .option('--page <n>', 'page number', (v) => parseInt(v, 10))
60
+ .option('--limit <n>', 'results per page (server default 50, max 200)', (v) => parseInt(v, 10))
61
+ .action(async (opts, cmd) => {
62
+ const g = cmd.optsWithGlobals();
63
+ const client = resolveClient(g.apiKey);
64
+ await run(() => handleInboxList(client, { page: opts.page, limit: opts.limit }, g.table ?? false));
65
+ });
66
+ const capture = inbox.command('capture').description('Capture a paper into the inbox');
67
+ capture
68
+ .command('doi')
69
+ .description('Capture by DOI')
70
+ .argument('<doi>')
71
+ .action(async (doi, _opts, cmd) => {
72
+ const g = cmd.optsWithGlobals();
73
+ const client = resolveClient(g.apiKey);
74
+ await run(() => handleInboxCaptureDoi(client, doi, g.table ?? false));
75
+ });
76
+ capture
77
+ .command('bibtex')
78
+ .description('Capture from a BibTeX string or file (bulk -- one inbox item per entry)')
79
+ .option('--bibtex <string>', 'inline BibTeX string')
80
+ .option('--file <path>', 'path to .bib file')
81
+ .action(async (opts, cmd) => {
82
+ const g = cmd.optsWithGlobals();
83
+ if (!opts.bibtex && !opts.file) {
84
+ process.stderr.write(JSON.stringify({ error: { code: 'missing_input', message: 'Provide --bibtex <string> or --file <path>.' } }) + '\n');
85
+ process.exit(2);
86
+ }
87
+ if (opts.bibtex && opts.file) {
88
+ process.stderr.write(JSON.stringify({ error: { code: 'conflicting_input', message: 'Pass --bibtex <string> or --file <path>, not both.' } }) + '\n');
89
+ process.exit(2);
90
+ }
91
+ let bibtex;
92
+ try {
93
+ bibtex = opts.file ? readFileSync(opts.file, 'utf8') : opts.bibtex;
94
+ }
95
+ catch (e) {
96
+ process.stderr.write(JSON.stringify({ error: { code: 'file_read_error', message: `Cannot read file: ${String(e)}` } }) + '\n');
97
+ process.exit(2);
98
+ }
99
+ const client = resolveClient(g.apiKey);
100
+ await run(() => handleInboxCaptureBibtex(client, bibtex, g.table ?? false));
101
+ });
102
+ capture
103
+ .command('manual')
104
+ .description('Capture a manual entry (title only)')
105
+ .requiredOption('--title <title>')
106
+ .action(async (opts, cmd) => {
107
+ const g = cmd.optsWithGlobals();
108
+ const client = resolveClient(g.apiKey);
109
+ await run(() => handleInboxCaptureManual(client, opts.title, g.table ?? false));
110
+ });
111
+ inbox
112
+ .command('accept')
113
+ .argument('<itemId>')
114
+ .description('File a pending item into a vault')
115
+ .requiredOption('--vault <id>')
116
+ .option('--tags <ids>', 'comma-separated tag IDs to attach')
117
+ .action(async (itemId, opts, cmd) => {
118
+ const g = cmd.optsWithGlobals();
119
+ const client = resolveClient(g.apiKey);
120
+ await run(() => handleInboxAccept(client, itemId, opts.vault, opts.tags, g.table ?? false));
121
+ });
122
+ inbox
123
+ .command('reject')
124
+ .argument('<itemId>')
125
+ .description('Discard a pending item (no undo)')
126
+ .option('--confirm', 'required: acknowledge there is no way to un-reject')
127
+ .action(async (itemId, opts, cmd) => {
128
+ const client = resolveClient(cmd.optsWithGlobals().apiKey);
129
+ await run(() => handleInboxReject(client, itemId, opts.confirm ?? false));
130
+ });
131
+ inbox
132
+ .command('merge')
133
+ .argument('<itemId>')
134
+ .description('File a pending item as a duplicate of the match RefHub already found (no undo)')
135
+ .option('--confirm', 'required: acknowledge there is no way to un-merge')
136
+ .action(async (itemId, opts, cmd) => {
137
+ const g = cmd.optsWithGlobals();
138
+ const client = resolveClient(g.apiKey);
139
+ await run(() => handleInboxMerge(client, itemId, opts.confirm ?? false, g.table ?? false));
140
+ });
141
+ inbox
142
+ .command('postpone')
143
+ .argument('<itemId>')
144
+ .description('Move a pending item to the back of the queue')
145
+ .action(async (itemId, _opts, cmd) => {
146
+ const g = cmd.optsWithGlobals();
147
+ const client = resolveClient(g.apiKey);
148
+ await run(() => handleInboxPostpone(client, itemId, g.table ?? false));
149
+ });
150
+ inbox
151
+ .command('delete')
152
+ .argument('<itemId>')
153
+ .description('Delete an inbox item regardless of status (hard delete, no undo)')
154
+ .option('--confirm', 'required: acknowledge this is a permanent deletion')
155
+ .action(async (itemId, opts, cmd) => {
156
+ const client = resolveClient(cmd.optsWithGlobals().apiKey);
157
+ await run(() => handleInboxDelete(client, itemId, opts.confirm ?? false));
158
+ });
159
+ }
@@ -1,5 +1,18 @@
1
- import type { Command } from 'commander';
1
+ import { type Command } from 'commander';
2
2
  import { RefHubClient } from '../client.js';
3
+ /** Collects a repeatable option into an array. */
4
+ export declare function collectOption(value: string, previous?: string[]): string[];
5
+ /**
6
+ * Parses --year. An empty value means "no year" (cleared on update, left out on add); it comes back
7
+ * as "" because commander replaces a parser's null with "".
8
+ */
9
+ export declare function parseYearOption(value: string): number | '';
10
+ /**
11
+ * The author list from --author (repeatable, one author each, commas kept) or --authors.
12
+ * --authors splits on ";" when the value has one, so "Last, First" names survive; otherwise it
13
+ * keeps splitting on commas as before, with a hint, so existing scripts behave the same.
14
+ */
15
+ export declare function resolveAuthors(author: string[] | undefined, authors: string | undefined): string[] | undefined;
3
16
  export declare function handleItemsList(client: RefHubClient, vaultId: string, opts: {
4
17
  page?: number;
5
18
  limit?: number;
@@ -7,8 +20,9 @@ export declare function handleItemsList(client: RefHubClient, vaultId: string, o
7
20
  export declare function handleItemGet(client: RefHubClient, vaultId: string, itemId: string, tableMode: boolean): Promise<void>;
8
21
  export declare function handleItemAdd(client: RefHubClient, vaultId: string, opts: {
9
22
  title: string;
23
+ author?: string[];
10
24
  authors?: string;
11
- year?: number;
25
+ year?: number | '' | null;
12
26
  doi?: string;
13
27
  url?: string;
14
28
  tags?: string;
@@ -17,13 +31,19 @@ export declare function handleItemAdd(client: RefHubClient, vaultId: string, opt
17
31
  }, tableMode: boolean): Promise<void>;
18
32
  export declare function handleItemUpdate(client: RefHubClient, vaultId: string, itemId: string, opts: {
19
33
  title?: string;
34
+ author?: string[];
20
35
  authors?: string;
21
- year?: number;
36
+ year?: number | '' | null;
22
37
  doi?: string;
23
38
  url?: string;
24
39
  tags?: string;
25
40
  notes?: string;
26
41
  pdfUrl?: string;
42
+ section?: string;
43
+ unsetSection?: boolean;
44
+ featured?: boolean;
45
+ unfeature?: boolean;
46
+ featuredNote?: string;
27
47
  }, tableMode: boolean): Promise<void>;
28
48
  export declare function handleItemDelete(client: RefHubClient, vaultId: string, itemId: string, confirmed: boolean): Promise<void>;
29
49
  export declare function handleItemUpsert(client: RefHubClient, vaultId: string, filePath: string, idempotencyKey: string | undefined, tableMode: boolean): Promise<void>;
@@ -1,7 +1,54 @@
1
1
  // src/commands/items.ts
2
2
  import { readFileSync } from 'fs';
3
+ import { InvalidArgumentError } from 'commander';
3
4
  import { resolveClient, run } from '../client.js';
4
5
  import { format } from '../format.js';
6
+ function usageError(code, message) {
7
+ process.stderr.write(JSON.stringify({ error: { code, message } }) + '\n');
8
+ process.exit(2);
9
+ }
10
+ /** Collects a repeatable option into an array. */
11
+ export function collectOption(value, previous = []) {
12
+ return [...previous, value];
13
+ }
14
+ /**
15
+ * Parses --year. An empty value means "no year" (cleared on update, left out on add); it comes back
16
+ * as "" because commander replaces a parser's null with "".
17
+ */
18
+ export function parseYearOption(value) {
19
+ if (value.trim() === '')
20
+ return '';
21
+ const year = Number(value);
22
+ if (!Number.isInteger(year))
23
+ throw new InvalidArgumentError('must be a whole year, e.g. 2024');
24
+ return year;
25
+ }
26
+ function splitList(value, separator) {
27
+ return value.split(separator).map((part) => part.trim()).filter(Boolean);
28
+ }
29
+ /**
30
+ * The author list from --author (repeatable, one author each, commas kept) or --authors.
31
+ * --authors splits on ";" when the value has one, so "Last, First" names survive; otherwise it
32
+ * keeps splitting on commas as before, with a hint, so existing scripts behave the same.
33
+ */
34
+ export function resolveAuthors(author, authors) {
35
+ if (author?.length && authors !== undefined) {
36
+ usageError('invalid_options', 'Pass either --author (repeatable) or --authors, not both.');
37
+ }
38
+ if (author?.length)
39
+ return author.map((name) => name.trim()).filter(Boolean);
40
+ if (authors === undefined)
41
+ return undefined;
42
+ const separator = authors.includes(';') ? ';' : ',';
43
+ const list = splitList(authors, separator);
44
+ if (separator === ',' && list.length > 1) {
45
+ process.stderr.write(JSON.stringify({
46
+ warning: 'authors_split_on_commas',
47
+ message: `--authors was split on commas into ${list.length} authors. For "Last, First" names, repeat --author once per author, or separate authors with ";".`,
48
+ }) + '\n');
49
+ }
50
+ return list;
51
+ }
5
52
  export async function handleItemsList(client, vaultId, opts, tableMode) {
6
53
  const result = await client.listItems(vaultId, opts);
7
54
  format(result, tableMode, ['id', 'title', 'authors', 'year', 'doi', 'updated_at']);
@@ -11,33 +58,43 @@ export async function handleItemGet(client, vaultId, itemId, tableMode) {
11
58
  format(result, tableMode);
12
59
  }
13
60
  export async function handleItemAdd(client, vaultId, opts, tableMode) {
61
+ // On add, an empty optional value is simply left out; the title is required.
62
+ if (!opts.title.trim())
63
+ usageError('invalid_value', '--title cannot be empty.');
14
64
  const item = { title: opts.title };
15
- if (opts.authors)
16
- item['authors'] = opts.authors.split(',').map((a) => a.trim());
17
- if (opts.year !== undefined)
65
+ const authors = resolveAuthors(opts.author, opts.authors);
66
+ if (authors?.length)
67
+ item['authors'] = authors;
68
+ if (typeof opts.year === 'number')
18
69
  item['year'] = opts.year;
19
70
  if (opts.doi)
20
71
  item['doi'] = opts.doi;
21
- if (opts.url !== undefined)
72
+ if (opts.url)
22
73
  item['url'] = opts.url;
23
- if (opts.tags)
24
- item['tag_ids'] = opts.tags.split(',').map((t) => t.trim());
25
- if (opts.notes !== undefined)
74
+ const tagIds = opts.tags ? splitList(opts.tags, ',') : [];
75
+ if (tagIds.length)
76
+ item['tag_ids'] = tagIds;
77
+ if (opts.notes)
26
78
  item['notes'] = opts.notes;
27
- if (opts.pdfUrl !== undefined)
79
+ if (opts.pdfUrl)
28
80
  item['pdf_url'] = opts.pdfUrl;
29
81
  const result = await client.addItems(vaultId, [item]);
30
82
  format(result, tableMode, ['id', 'title', 'doi', 'year']);
31
83
  }
32
84
  export async function handleItemUpdate(client, vaultId, itemId, opts, tableMode) {
85
+ // On update, an empty value clears an optional field; the title can't be cleared.
33
86
  const body = {};
34
- if (opts.title)
87
+ if (opts.title !== undefined) {
88
+ if (!opts.title.trim())
89
+ usageError('invalid_value', '--title cannot be empty; every item needs a title.');
35
90
  body['title'] = opts.title;
36
- if (opts.authors)
37
- body['authors'] = opts.authors.split(',').map((a) => a.trim());
91
+ }
92
+ const authors = resolveAuthors(opts.author, opts.authors);
93
+ if (authors !== undefined)
94
+ body['authors'] = authors;
38
95
  if (opts.year !== undefined)
39
- body['year'] = opts.year;
40
- if (opts.doi)
96
+ body['year'] = opts.year === '' ? null : opts.year;
97
+ if (opts.doi !== undefined)
41
98
  body['doi'] = opts.doi;
42
99
  if (opts.url !== undefined)
43
100
  body['url'] = opts.url;
@@ -45,10 +102,20 @@ export async function handleItemUpdate(client, vaultId, itemId, opts, tableMode)
45
102
  body['notes'] = opts.notes;
46
103
  if (opts.pdfUrl !== undefined)
47
104
  body['pdf_url'] = opts.pdfUrl;
48
- if (opts.tags) {
105
+ if (opts.tags !== undefined) {
49
106
  process.stderr.write(JSON.stringify({ warning: 'tag_replacement', message: '--tags replaces the full tag set, not an append. Existing tags will be removed.' }) + '\n');
50
- body['tag_ids'] = opts.tags.split(',').map((t) => t.trim());
107
+ body['tag_ids'] = splitList(opts.tags, ',');
51
108
  }
109
+ if (opts.section !== undefined)
110
+ body['section_id'] = opts.section;
111
+ if (opts.unsetSection)
112
+ body['section_id'] = null;
113
+ if (opts.featured)
114
+ body['featured'] = true;
115
+ if (opts.unfeature)
116
+ body['featured'] = false;
117
+ if (opts.featuredNote !== undefined)
118
+ body['featured_note'] = opts.featuredNote;
52
119
  const result = await client.updateItem(vaultId, itemId, body);
53
120
  format(result, tableMode);
54
121
  }
@@ -126,8 +193,9 @@ export function registerItems(program) {
126
193
  .description('Add an item to a vault')
127
194
  .requiredOption('--vault <id>')
128
195
  .requiredOption('--title <title>')
129
- .option('--authors <authors>', 'comma-separated, e.g. "Smith J,Doe A"')
130
- .option('--year <year>', 'publication year', (v) => parseInt(v, 10))
196
+ .option('--author <name>', 'one author; repeat for each (commas allowed: "Smith, John")', collectOption)
197
+ .option('--authors <authors>', 'all authors: separate with ";" ("Smith, John; Doe, Jane"); without ";", commas separate authors')
198
+ .option('--year <year>', 'publication year', parseYearOption)
131
199
  .option('--doi <doi>')
132
200
  .option('--url <url>', 'publication URL')
133
201
  .option('--tags <ids>', 'comma-separated tag IDs')
@@ -136,7 +204,7 @@ export function registerItems(program) {
136
204
  .action(async (opts, cmd) => {
137
205
  const g = cmd.optsWithGlobals();
138
206
  const client = resolveClient(g.apiKey);
139
- await run(() => handleItemAdd(client, opts.vault, { title: opts.title, authors: opts.authors, year: opts.year, doi: opts.doi, url: opts.url, tags: opts.tags, notes: opts.notes, pdfUrl: opts.pdfUrl }, g.table ?? false));
207
+ await run(() => handleItemAdd(client, opts.vault, { title: opts.title, author: opts.author, authors: opts.authors, year: opts.year, doi: opts.doi, url: opts.url, tags: opts.tags, notes: opts.notes, pdfUrl: opts.pdfUrl }, g.table ?? false));
140
208
  });
141
209
  items
142
210
  .command('update')
@@ -144,17 +212,34 @@ export function registerItems(program) {
144
212
  .description('Update an item')
145
213
  .requiredOption('--vault <id>')
146
214
  .option('--title <title>')
147
- .option('--authors <authors>')
148
- .option('--year <year>', '', (v) => parseInt(v, 10))
149
- .option('--doi <doi>')
215
+ .option('--author <name>', 'one author; repeat for each (commas allowed). Replaces the author list', collectOption)
216
+ .option('--authors <authors>', 'all authors: separate with ";"; without ";", commas separate authors. "" clears them')
217
+ .option('--year <year>', 'publication year; "" clears it', parseYearOption)
218
+ .option('--doi <doi>', 'DOI; "" clears it')
150
219
  .option('--url <url>', 'publication URL')
151
220
  .option('--tags <ids>', 'comma-separated tag IDs — REPLACES the full tag set')
152
221
  .option('--notes <text>', 'free-text notes on the item')
153
222
  .option('--pdf-url <url>', "publisher PDF link (the frontend's publisher_pdf field)")
223
+ .option('--section <sectionId>', 'file this item under a curated section — requires vault owner access')
224
+ .option('--unset-section', 'remove this item from its current section — requires vault owner access')
225
+ .option('--featured', 'mark this item as featured — requires vault owner access')
226
+ .option('--unfeature', 'remove this item from featured — requires vault owner access')
227
+ .option('--featured-note <text>', 'curator note shown alongside the featured item — requires vault owner access')
154
228
  .action(async (itemId, opts, cmd) => {
229
+ if (opts.section && opts.unsetSection) {
230
+ process.stderr.write(JSON.stringify({ error: { code: 'invalid_options', message: 'Pass at most one of --section or --unset-section.' } }) + '\n');
231
+ process.exit(2);
232
+ }
233
+ if (opts.featured && opts.unfeature) {
234
+ process.stderr.write(JSON.stringify({ error: { code: 'invalid_options', message: 'Pass at most one of --featured or --unfeature.' } }) + '\n');
235
+ process.exit(2);
236
+ }
155
237
  const g = cmd.optsWithGlobals();
156
238
  const client = resolveClient(g.apiKey);
157
- await run(() => handleItemUpdate(client, opts.vault, itemId, { title: opts.title, authors: opts.authors, year: opts.year, doi: opts.doi, url: opts.url, tags: opts.tags, notes: opts.notes, pdfUrl: opts.pdfUrl }, g.table ?? false));
239
+ await run(() => handleItemUpdate(client, opts.vault, itemId, {
240
+ title: opts.title, author: opts.author, authors: opts.authors, year: opts.year, doi: opts.doi, url: opts.url, tags: opts.tags, notes: opts.notes, pdfUrl: opts.pdfUrl,
241
+ section: opts.section, unsetSection: opts.unsetSection, featured: opts.featured, unfeature: opts.unfeature, featuredNote: opts.featuredNote,
242
+ }, g.table ?? false));
158
243
  });
159
244
  items
160
245
  .command('delete')
@@ -1,5 +1,6 @@
1
1
  import { resolveClient, run } from '../client.js';
2
2
  import { format } from '../format.js';
3
+ import { registerRelationsScan } from './relationsScan.js';
3
4
  const RELATION_TYPES = 'cites|extends|builds_on|contradicts|reviews|related';
4
5
  export async function handleRelationsList(client, vaultId, type, tableMode) {
5
6
  const result = await client.listRelations(vaultId, type);
@@ -66,4 +67,5 @@ export function registerRelations(program) {
66
67
  const client = resolveClient(g.apiKey);
67
68
  await run(() => handleRelationDelete(client, opts.vault, relationId));
68
69
  });
70
+ registerRelationsScan(relations);
69
71
  }
@@ -0,0 +1,23 @@
1
+ import type { Command } from 'commander';
2
+ import { RefHubClient } from '../client.js';
3
+ import type { Item, Relation, SemanticScholarPaper } from '../types.js';
4
+ export declare function findMatchingItem(paper: SemanticScholarPaper, items: Item[], excludeId: string): Item | undefined;
5
+ export type ScanOutcome = 'skipped_no_doi' | 'lookup_failed' | 'no_matches' | 'scanned';
6
+ export interface ScanItemResult {
7
+ outcome: ScanOutcome;
8
+ suggested: number;
9
+ created: number;
10
+ skippedDuplicate: number;
11
+ }
12
+ /**
13
+ * Scans one item's Semantic Scholar references (papers it cites) and
14
+ * citations (papers that cite it), matches each against `allItems`, and
15
+ * creates a "cites" relation for every new match. `existingRelations` is
16
+ * mutated with pending creations so a whole-vault scan doesn't propose the
17
+ * same pair twice across items.
18
+ */
19
+ export declare function scanItemRelations(item: Item, client: RefHubClient, vaultId: string, allItems: Item[], existingRelations: Relation[], opts: {
20
+ dryRun: boolean;
21
+ limit?: number;
22
+ }): Promise<ScanItemResult>;
23
+ export declare function registerRelationsScan(relations: Command): void;
@@ -0,0 +1,137 @@
1
+ import { resolveClient, run } from '../client.js';
2
+ function normalizeDoi(doi) {
3
+ return doi.trim().toLowerCase().replace(/^https?:\/\/(dx\.)?doi\.org\//, '');
4
+ }
5
+ function normalizeTitle(title) {
6
+ return title.trim().toLowerCase().replace(/\s+/g, ' ');
7
+ }
8
+ export function findMatchingItem(paper, items, excludeId) {
9
+ const paperDoi = paper.external_ids?.['DOI'] ?? paper.external_ids?.['doi'];
10
+ if (paperDoi) {
11
+ const normalized = normalizeDoi(paperDoi);
12
+ const doiMatch = items.find((i) => i.id !== excludeId && i.doi && normalizeDoi(i.doi) === normalized);
13
+ if (doiMatch)
14
+ return doiMatch;
15
+ }
16
+ if (paper.title) {
17
+ const normalized = normalizeTitle(paper.title);
18
+ return items.find((i) => i.id !== excludeId && i.title && normalizeTitle(i.title) === normalized);
19
+ }
20
+ return undefined;
21
+ }
22
+ function relationExists(relations, publicationId, relatedPublicationId) {
23
+ return relations.some((r) => r.publication_id === publicationId && r.related_publication_id === relatedPublicationId);
24
+ }
25
+ /**
26
+ * Scans one item's Semantic Scholar references (papers it cites) and
27
+ * citations (papers that cite it), matches each against `allItems`, and
28
+ * creates a "cites" relation for every new match. `existingRelations` is
29
+ * mutated with pending creations so a whole-vault scan doesn't propose the
30
+ * same pair twice across items.
31
+ */
32
+ export async function scanItemRelations(item, client, vaultId, allItems, existingRelations, opts) {
33
+ if (!item.doi)
34
+ return { outcome: 'skipped_no_doi', suggested: 0, created: 0, skippedDuplicate: 0 };
35
+ const lookup = await client.semanticScholarLookup({ doi: item.doi });
36
+ const paperId = lookup.data.paper_id;
37
+ if (!paperId)
38
+ return { outcome: 'lookup_failed', suggested: 0, created: 0, skippedDuplicate: 0 };
39
+ const [referencesResult, citationsResult] = await Promise.all([
40
+ client.semanticScholarPaperList('references', paperId, opts.limit),
41
+ client.semanticScholarPaperList('citations', paperId, opts.limit),
42
+ ]);
43
+ let suggested = 0;
44
+ let created = 0;
45
+ let skippedDuplicate = 0;
46
+ // references: this item cites the matched paper
47
+ for (const paper of referencesResult.data) {
48
+ const matched = findMatchingItem(paper, allItems, item.id);
49
+ if (!matched)
50
+ continue;
51
+ suggested++;
52
+ if (relationExists(existingRelations, item.id, matched.id)) {
53
+ skippedDuplicate++;
54
+ continue;
55
+ }
56
+ if (!opts.dryRun) {
57
+ await client.createRelation(vaultId, { publication_id: item.id, related_publication_id: matched.id, relation_type: 'cites' });
58
+ }
59
+ existingRelations.push({ id: 'pending', vault_id: vaultId, publication_id: item.id, related_publication_id: matched.id, relation_type: 'cites', created_at: '', updated_at: '' });
60
+ created++;
61
+ }
62
+ // citations: the matched paper cites this item
63
+ for (const paper of citationsResult.data) {
64
+ const matched = findMatchingItem(paper, allItems, item.id);
65
+ if (!matched)
66
+ continue;
67
+ suggested++;
68
+ if (relationExists(existingRelations, matched.id, item.id)) {
69
+ skippedDuplicate++;
70
+ continue;
71
+ }
72
+ if (!opts.dryRun) {
73
+ await client.createRelation(vaultId, { publication_id: matched.id, related_publication_id: item.id, relation_type: 'cites' });
74
+ }
75
+ existingRelations.push({ id: 'pending', vault_id: vaultId, publication_id: matched.id, related_publication_id: item.id, relation_type: 'cites', created_at: '', updated_at: '' });
76
+ created++;
77
+ }
78
+ return { outcome: suggested === 0 ? 'no_matches' : 'scanned', suggested, created, skippedDuplicate };
79
+ }
80
+ export function registerRelationsScan(relations) {
81
+ relations
82
+ .command('scan')
83
+ .description('Scan Semantic Scholar references/citations and create "cites" relations to sibling items in this vault, matched by DOI or exact title')
84
+ .requiredOption('--vault <id>')
85
+ .option('--item <itemId>', 'scan a single item instead of the whole vault')
86
+ .option('--dry-run', 'show what would be created without writing')
87
+ .option('--limit <n>', 'references/citations fetched per item from Semantic Scholar, 1-25', (v) => parseInt(v, 10))
88
+ .action(async (opts, cmd) => {
89
+ const g = cmd.optsWithGlobals();
90
+ const client = resolveClient(g.apiKey);
91
+ const dryRun = opts.dryRun ?? false;
92
+ await run(async () => {
93
+ const vaultResult = await client.getVault(opts.vault);
94
+ const allItems = vaultResult.data.items;
95
+ const existingRelations = [...vaultResult.data.relations];
96
+ const targets = opts.item ? allItems.filter((i) => i.id === opts.item) : allItems;
97
+ if (opts.item && targets.length === 0) {
98
+ process.stderr.write(JSON.stringify({ error: { code: 'item_not_found', message: `Item ${opts.item} not found in vault ${opts.vault}.` } }) + '\n');
99
+ process.exit(2);
100
+ }
101
+ const withDoi = targets.filter((i) => i.doi);
102
+ if (withDoi.length === 0) {
103
+ process.stdout.write(JSON.stringify({ data: { dry_run: dryRun, scanned: 0, suggested: 0, created: 0, skipped_duplicate: 0, no_doi: targets.length, message: 'No items with a DOI to scan.' } }, null, 2) + '\n');
104
+ return;
105
+ }
106
+ let suggested = 0;
107
+ let created = 0;
108
+ let skippedDuplicate = 0;
109
+ let noMatches = 0;
110
+ let lookupFailed = 0;
111
+ for (const item of withDoi) {
112
+ const result = await scanItemRelations(item, client, opts.vault, allItems, existingRelations, { dryRun, limit: opts.limit });
113
+ suggested += result.suggested;
114
+ created += result.created;
115
+ skippedDuplicate += result.skippedDuplicate;
116
+ if (result.outcome === 'no_matches')
117
+ noMatches++;
118
+ if (result.outcome === 'lookup_failed')
119
+ lookupFailed++;
120
+ // pace Semantic Scholar calls — each item makes a lookup + references + citations request
121
+ await new Promise((r) => setTimeout(r, 1000));
122
+ }
123
+ process.stdout.write(JSON.stringify({
124
+ data: {
125
+ dry_run: dryRun,
126
+ scanned: withDoi.length,
127
+ no_doi: targets.length - withDoi.length,
128
+ lookup_failed: lookupFailed,
129
+ no_matches: noMatches,
130
+ suggested,
131
+ created,
132
+ skipped_duplicate: skippedDuplicate,
133
+ },
134
+ }, null, 2) + '\n');
135
+ });
136
+ });
137
+ }
@@ -0,0 +1,15 @@
1
+ import type { Command } from 'commander';
2
+ import { RefHubClient } from '../client.js';
3
+ export declare function handleSectionsList(client: RefHubClient, vaultId: string, tableMode: boolean): Promise<void>;
4
+ export declare function handleSectionCreate(client: RefHubClient, vaultId: string, opts: {
5
+ name: string;
6
+ description?: string;
7
+ position?: number;
8
+ }, tableMode: boolean): Promise<void>;
9
+ export declare function handleSectionUpdate(client: RefHubClient, vaultId: string, sectionId: string, opts: {
10
+ name?: string;
11
+ description?: string;
12
+ position?: number;
13
+ }, tableMode: boolean): Promise<void>;
14
+ export declare function handleSectionDelete(client: RefHubClient, vaultId: string, sectionId: string): Promise<void>;
15
+ export declare function registerSections(program: Command): void;
@@ -0,0 +1,77 @@
1
+ import { resolveClient, run } from '../client.js';
2
+ import { format } from '../format.js';
3
+ export async function handleSectionsList(client, vaultId, tableMode) {
4
+ const result = await client.listSections(vaultId);
5
+ format(result, tableMode, ['id', 'name', 'description', 'position']);
6
+ }
7
+ export async function handleSectionCreate(client, vaultId, opts, tableMode) {
8
+ const body = { name: opts.name };
9
+ if (opts.description !== undefined)
10
+ body.description = opts.description;
11
+ if (opts.position !== undefined)
12
+ body.position = opts.position;
13
+ const result = await client.createSection(vaultId, body);
14
+ format(result, tableMode);
15
+ }
16
+ export async function handleSectionUpdate(client, vaultId, sectionId, opts, tableMode) {
17
+ const body = {};
18
+ if (opts.name !== undefined)
19
+ body.name = opts.name;
20
+ if (opts.description !== undefined)
21
+ body.description = opts.description;
22
+ if (opts.position !== undefined)
23
+ body.position = opts.position;
24
+ const result = await client.updateSection(vaultId, sectionId, body);
25
+ format(result, tableMode);
26
+ }
27
+ export async function handleSectionDelete(client, vaultId, sectionId) {
28
+ const result = await client.deleteSection(vaultId, sectionId);
29
+ format(result, false);
30
+ }
31
+ export function registerSections(program) {
32
+ const sections = program.command('sections').description('Manage curated vault sections (owner-only writes)');
33
+ sections
34
+ .command('list')
35
+ .description('List sections in a vault')
36
+ .requiredOption('--vault <id>')
37
+ .action(async (opts, cmd) => {
38
+ const g = cmd.optsWithGlobals();
39
+ const client = resolveClient(g.apiKey);
40
+ await run(() => handleSectionsList(client, opts.vault, g.table ?? false));
41
+ });
42
+ sections
43
+ .command('create')
44
+ .description('Create a section (owner-only)')
45
+ .requiredOption('--vault <id>')
46
+ .requiredOption('--name <name>')
47
+ .option('--description <text>')
48
+ .option('--position <n>', 'sort position, defaults to 0', (v) => parseInt(v, 10))
49
+ .action(async (opts, cmd) => {
50
+ const g = cmd.optsWithGlobals();
51
+ const client = resolveClient(g.apiKey);
52
+ await run(() => handleSectionCreate(client, opts.vault, { name: opts.name, description: opts.description, position: opts.position }, g.table ?? false));
53
+ });
54
+ sections
55
+ .command('update')
56
+ .argument('<sectionId>')
57
+ .description('Update a section (owner-only)')
58
+ .requiredOption('--vault <id>')
59
+ .option('--name <name>')
60
+ .option('--description <text>')
61
+ .option('--position <n>', '', (v) => parseInt(v, 10))
62
+ .action(async (sectionId, opts, cmd) => {
63
+ const g = cmd.optsWithGlobals();
64
+ const client = resolveClient(g.apiKey);
65
+ await run(() => handleSectionUpdate(client, opts.vault, sectionId, { name: opts.name, description: opts.description, position: opts.position }, g.table ?? false));
66
+ });
67
+ sections
68
+ .command('delete')
69
+ .argument('<sectionId>')
70
+ .description('Delete a section (owner-only) — items in it are unfiled, not deleted')
71
+ .requiredOption('--vault <id>')
72
+ .action(async (sectionId, opts, cmd) => {
73
+ const g = cmd.optsWithGlobals();
74
+ const client = resolveClient(g.apiKey);
75
+ await run(() => handleSectionDelete(client, opts.vault, sectionId));
76
+ });
77
+ }
package/dist/index.js CHANGED
@@ -4,6 +4,7 @@ import { createRequire } from 'module';
4
4
  import { registerVaults } from './commands/vaults.js';
5
5
  import { registerItems } from './commands/items.js';
6
6
  import { registerTags } from './commands/tags.js';
7
+ import { registerSections } from './commands/sections.js';
7
8
  import { registerRelations } from './commands/relations.js';
8
9
  import { registerImport } from './commands/import.js';
9
10
  import { registerExport } from './commands/export.js';
@@ -11,6 +12,7 @@ import { registerAudit } from './commands/audit.js';
11
12
  import { registerEnrich } from './commands/enrich.js';
12
13
  import { registerPdf } from './commands/pdf.js';
13
14
  import { registerDiscover } from './commands/discover.js';
15
+ import { registerInbox } from './commands/inbox.js';
14
16
  const require = createRequire(import.meta.url);
15
17
  const { version } = require('../package.json');
16
18
  const program = new Command();
@@ -23,6 +25,7 @@ program
23
25
  registerVaults(program);
24
26
  registerItems(program);
25
27
  registerTags(program);
28
+ registerSections(program);
26
29
  registerRelations(program);
27
30
  registerImport(program);
28
31
  registerExport(program);
@@ -30,4 +33,5 @@ registerAudit(program);
30
33
  registerEnrich(program);
31
34
  registerDiscover(program);
32
35
  registerPdf(program);
36
+ registerInbox(program);
33
37
  program.parseAsync();
package/dist/types.d.ts CHANGED
@@ -29,10 +29,23 @@ export interface Item {
29
29
  pdf_url?: string;
30
30
  drive_pdf_url?: string | null;
31
31
  tag_ids: string[];
32
+ section_id?: string | null;
33
+ section_position?: number;
34
+ featured?: boolean;
35
+ featured_note?: string | null;
32
36
  version: number;
33
37
  created_at: string;
34
38
  updated_at: string;
35
39
  }
40
+ export interface Section {
41
+ id: string;
42
+ vault_id: string;
43
+ name: string;
44
+ description?: string | null;
45
+ position: number;
46
+ created_at: string;
47
+ updated_at: string;
48
+ }
36
49
  export interface Tag {
37
50
  id: string;
38
51
  vault_id: string;
@@ -100,6 +113,22 @@ export interface AuditEntry {
100
113
  metadata?: Record<string, unknown>;
101
114
  created_at: string;
102
115
  }
116
+ export type InboxSourceType = 'doi' | 'bibtex' | 'manual';
117
+ export type InboxItemStatus = 'pending' | 'accepted' | 'rejected' | 'merged';
118
+ export interface InboxItem {
119
+ id: string;
120
+ status: InboxItemStatus;
121
+ source_type: InboxSourceType;
122
+ source_ref: string;
123
+ parsed_fields: Record<string, unknown>;
124
+ suggested_vault_id: string | null;
125
+ suggested_tag_ids: string[] | null;
126
+ duplicate_of_publication_id: string | null;
127
+ filed_publication_id: string | null;
128
+ sort_order: number;
129
+ created_at: string;
130
+ updated_at: string;
131
+ }
103
132
  export interface ApiResponse<T> {
104
133
  data: T;
105
134
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@refhub/cli",
3
- "version": "1.6.0",
3
+ "version": "1.8.0",
4
4
  "description": "refhub CLI execution layer for agent skills",
5
5
  "type": "module",
6
6
  "repository": {
@@ -11,16 +11,24 @@
11
11
  "bugs": {
12
12
  "url": "https://github.com/refhub-io/refhub-cli/issues"
13
13
  },
14
- "engines": { "node": ">=18" },
15
- "bin": { "refhub": "bin/refhub.js" },
14
+ "engines": {
15
+ "node": ">=18"
16
+ },
17
+ "bin": {
18
+ "refhub": "bin/refhub.js"
19
+ },
16
20
  "scripts": {
17
21
  "build": "tsc",
22
+ "prepare": "npm run build",
18
23
  "test": "vitest run",
19
24
  "test:watch": "vitest",
20
25
  "smoke": "tsx scripts/smoke.ts",
21
26
  "dev": "tsx src/index.ts"
22
27
  },
23
- "files": ["dist", "bin"],
28
+ "files": [
29
+ "dist",
30
+ "bin"
31
+ ],
24
32
  "publishConfig": {
25
33
  "access": "public"
26
34
  },