@refhub/cli 1.7.0 → 1.8.1

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] [--section <sectionId> | --unset-section] [--featured | --unfeature] [--featured-note <text>]
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,10 @@ 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
+
109
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.
110
114
 
111
115
  ### sections
package/dist/client.js CHANGED
@@ -190,7 +190,7 @@ export class RefHubClient {
190
190
  if (params.page !== undefined)
191
191
  q.set('page', String(params.page));
192
192
  if (params.limit !== undefined)
193
- q.set('limit', String(params.limit));
193
+ q.set('per_page', String(params.limit));
194
194
  const qs = q.toString() ? `?${q}` : '';
195
195
  return this.req('GET', `/inbox${qs}`);
196
196
  }
@@ -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,8 +31,9 @@ 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;
@@ -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,9 +102,9 @@ 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
  }
52
109
  if (opts.section !== undefined)
53
110
  body['section_id'] = opts.section;
@@ -136,8 +193,9 @@ export function registerItems(program) {
136
193
  .description('Add an item to a vault')
137
194
  .requiredOption('--vault <id>')
138
195
  .requiredOption('--title <title>')
139
- .option('--authors <authors>', 'comma-separated, e.g. "Smith J,Doe A"')
140
- .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)
141
199
  .option('--doi <doi>')
142
200
  .option('--url <url>', 'publication URL')
143
201
  .option('--tags <ids>', 'comma-separated tag IDs')
@@ -146,7 +204,7 @@ export function registerItems(program) {
146
204
  .action(async (opts, cmd) => {
147
205
  const g = cmd.optsWithGlobals();
148
206
  const client = resolveClient(g.apiKey);
149
- 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));
150
208
  });
151
209
  items
152
210
  .command('update')
@@ -154,9 +212,10 @@ export function registerItems(program) {
154
212
  .description('Update an item')
155
213
  .requiredOption('--vault <id>')
156
214
  .option('--title <title>')
157
- .option('--authors <authors>')
158
- .option('--year <year>', '', (v) => parseInt(v, 10))
159
- .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')
160
219
  .option('--url <url>', 'publication URL')
161
220
  .option('--tags <ids>', 'comma-separated tag IDs — REPLACES the full tag set')
162
221
  .option('--notes <text>', 'free-text notes on the item')
@@ -178,7 +237,7 @@ export function registerItems(program) {
178
237
  const g = cmd.optsWithGlobals();
179
238
  const client = resolveClient(g.apiKey);
180
239
  await run(() => handleItemUpdate(client, opts.vault, itemId, {
181
- title: opts.title, authors: opts.authors, year: opts.year, doi: opts.doi, url: opts.url, tags: opts.tags, notes: opts.notes, pdfUrl: opts.pdfUrl,
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,
182
241
  section: opts.section, unsetSection: opts.unsetSection, featured: opts.featured, unfeature: opts.unfeature, featuredNote: opts.featuredNote,
183
242
  }, g.table ?? false));
184
243
  });
@@ -1,4 +1,4 @@
1
- import type { Command } from 'commander';
1
+ import { type Command } from 'commander';
2
2
  import { RefHubClient } from '../client.js';
3
3
  export declare function handleRelationsList(client: RefHubClient, vaultId: string, type: string | undefined, tableMode: boolean): Promise<void>;
4
4
  export declare function handleRelationCreate(client: RefHubClient, vaultId: string, opts: {
@@ -1,7 +1,11 @@
1
+ // src/commands/relations.ts
2
+ import { Option } from 'commander';
1
3
  import { resolveClient, run } from '../client.js';
2
4
  import { format } from '../format.js';
3
5
  import { registerRelationsScan } from './relationsScan.js';
4
- const RELATION_TYPES = 'cites|extends|builds_on|contradicts|reviews|related';
6
+ import { RELATION_TYPES } from '../types.js';
7
+ // commander refuses any other value, and lists these in its error and in --help.
8
+ const typeOption = () => new Option('--type <type>', 'relation type').choices(RELATION_TYPES);
5
9
  export async function handleRelationsList(client, vaultId, type, tableMode) {
6
10
  const result = await client.listRelations(vaultId, type);
7
11
  format(result, tableMode, ['id', 'publication_id', 'related_publication_id', 'relation_type']);
@@ -28,7 +32,7 @@ export function registerRelations(program) {
28
32
  .command('list')
29
33
  .description('List relations in a vault')
30
34
  .requiredOption('--vault <id>')
31
- .option('--type <type>', RELATION_TYPES)
35
+ .addOption(typeOption())
32
36
  .action(async (opts, cmd) => {
33
37
  const g = cmd.optsWithGlobals();
34
38
  const client = resolveClient(g.apiKey);
@@ -40,7 +44,7 @@ export function registerRelations(program) {
40
44
  .requiredOption('--vault <id>')
41
45
  .requiredOption('--pub <publicationId>')
42
46
  .requiredOption('--related <publicationId>')
43
- .option('--type <type>', RELATION_TYPES)
47
+ .addOption(typeOption())
44
48
  .action(async (opts, cmd) => {
45
49
  const g = cmd.optsWithGlobals();
46
50
  const client = resolveClient(g.apiKey);
@@ -51,7 +55,7 @@ export function registerRelations(program) {
51
55
  .argument('<relationId>')
52
56
  .description('Update a relation type')
53
57
  .requiredOption('--vault <id>')
54
- .requiredOption('--type <type>', RELATION_TYPES)
58
+ .addOption(typeOption().makeOptionMandatory())
55
59
  .action(async (relationId, opts, cmd) => {
56
60
  const g = cmd.optsWithGlobals();
57
61
  const client = resolveClient(g.apiKey);
@@ -56,7 +56,7 @@ export async function scanItemRelations(item, client, vaultId, allItems, existin
56
56
  if (!opts.dryRun) {
57
57
  await client.createRelation(vaultId, { publication_id: item.id, related_publication_id: matched.id, relation_type: 'cites' });
58
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: '' });
59
+ existingRelations.push({ id: 'pending', publication_id: item.id, related_publication_id: matched.id, relation_type: 'cites', created_at: '' });
60
60
  created++;
61
61
  }
62
62
  // citations: the matched paper cites this item
@@ -72,7 +72,7 @@ export async function scanItemRelations(item, client, vaultId, allItems, existin
72
72
  if (!opts.dryRun) {
73
73
  await client.createRelation(vaultId, { publication_id: matched.id, related_publication_id: item.id, relation_type: 'cites' });
74
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: '' });
75
+ existingRelations.push({ id: 'pending', publication_id: matched.id, related_publication_id: item.id, relation_type: 'cites', created_at: '' });
76
76
  created++;
77
77
  }
78
78
  return { outcome: suggested === 0 ? 'no_matches' : 'scanned', suggested, created, skippedDuplicate };
package/dist/types.d.ts CHANGED
@@ -1,4 +1,6 @@
1
- export type RelationType = 'cites' | 'extends' | 'builds_on' | 'contradicts' | 'reviews' | 'related';
1
+ /** The relation types the API accepts, in the order help text lists them (refhub-io/.netlify#48). */
2
+ export declare const RELATION_TYPES: readonly ["cites", "extends", "builds_on", "contradicts", "reviews", "related"];
3
+ export type RelationType = (typeof RELATION_TYPES)[number];
2
4
  export interface Vault {
3
5
  id: string;
4
6
  name: string;
@@ -46,23 +48,23 @@ export interface Section {
46
48
  created_at: string;
47
49
  updated_at: string;
48
50
  }
51
+ /** As the API returns it: tags carry no vault id or update time. */
49
52
  export interface Tag {
50
53
  id: string;
51
- vault_id: string;
52
54
  name: string;
53
55
  color?: string;
54
- parent_id?: string;
56
+ parent_id?: string | null;
57
+ depth?: number;
55
58
  created_at: string;
56
- updated_at: string;
57
59
  }
60
+ /** As the API returns it: a relation belongs to its papers, not to a vault, and isn't updated in place. */
58
61
  export interface Relation {
59
62
  id: string;
60
- vault_id: string;
61
63
  publication_id: string;
62
64
  related_publication_id: string;
63
65
  relation_type: RelationType;
64
66
  created_at: string;
65
- updated_at: string;
67
+ created_by?: string | null;
66
68
  }
67
69
  export interface Share {
68
70
  id: string;
package/dist/types.js CHANGED
@@ -1 +1,2 @@
1
- export {};
1
+ /** The relation types the API accepts, in the order help text lists them (refhub-io/.netlify#48). */
2
+ export const RELATION_TYPES = ['cites', 'extends', 'builds_on', 'contradicts', 'reviews', 'related'];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@refhub/cli",
3
- "version": "1.7.0",
3
+ "version": "1.8.1",
4
4
  "description": "refhub CLI execution layer for agent skills",
5
5
  "type": "module",
6
6
  "repository": {
@@ -19,6 +19,7 @@
19
19
  },
20
20
  "scripts": {
21
21
  "build": "tsc",
22
+ "prepare": "npm run build",
22
23
  "test": "vitest run",
23
24
  "test:watch": "vitest",
24
25
  "smoke": "tsx scripts/smoke.ts",