@refhub/cli 1.0.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 +212 -0
- package/dist/client.d.ts +136 -0
- package/dist/client.js +223 -0
- package/dist/commands/audit.d.ts +9 -0
- package/dist/commands/audit.js +21 -0
- package/dist/commands/export.d.ts +4 -0
- package/dist/commands/export.js +22 -0
- package/dist/commands/import.d.ts +6 -0
- package/dist/commands/import.js +74 -0
- package/dist/commands/items.d.ts +36 -0
- package/dist/commands/items.js +208 -0
- package/dist/commands/relations.d.ts +11 -0
- package/dist/commands/relations.js +69 -0
- package/dist/commands/tags.d.ts +17 -0
- package/dist/commands/tags.js +109 -0
- package/dist/commands/vaults.d.ts +33 -0
- package/dist/commands/vaults.js +183 -0
- package/dist/format.d.ts +1 -0
- package/dist/format.js +22 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +25 -0
- package/dist/types.d.ts +99 -0
- package/dist/types.js +1 -0
- package/package.json +30 -0
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { resolveClient, run } from '../client.js';
|
|
2
|
+
import { format } from '../format.js';
|
|
3
|
+
export async function handleVaultsList(client, tableMode) {
|
|
4
|
+
const result = await client.listVaults();
|
|
5
|
+
format(result, tableMode, ['id', 'name', 'visibility', 'item_count', 'updated_at']);
|
|
6
|
+
}
|
|
7
|
+
export async function handleVaultGet(client, vaultId, tableMode) {
|
|
8
|
+
const result = await client.getVault(vaultId);
|
|
9
|
+
format(result, tableMode);
|
|
10
|
+
}
|
|
11
|
+
export async function handleVaultCreate(client, opts, tableMode) {
|
|
12
|
+
const body = { name: opts.name };
|
|
13
|
+
if (opts.description)
|
|
14
|
+
body['description'] = opts.description;
|
|
15
|
+
if (opts.color)
|
|
16
|
+
body['color'] = opts.color;
|
|
17
|
+
if (opts.visibility)
|
|
18
|
+
body['visibility'] = opts.visibility;
|
|
19
|
+
if (opts.category)
|
|
20
|
+
body['category'] = opts.category;
|
|
21
|
+
if (opts.abstract)
|
|
22
|
+
body['abstract'] = opts.abstract;
|
|
23
|
+
const result = await client.createVault(body);
|
|
24
|
+
format(result, tableMode);
|
|
25
|
+
}
|
|
26
|
+
export async function handleVaultUpdate(client, vaultId, opts, tableMode) {
|
|
27
|
+
const body = {};
|
|
28
|
+
if (opts.name)
|
|
29
|
+
body['name'] = opts.name;
|
|
30
|
+
if (opts.description)
|
|
31
|
+
body['description'] = opts.description;
|
|
32
|
+
if (opts.color)
|
|
33
|
+
body['color'] = opts.color;
|
|
34
|
+
if (opts.category)
|
|
35
|
+
body['category'] = opts.category;
|
|
36
|
+
if (opts.abstract)
|
|
37
|
+
body['abstract'] = opts.abstract;
|
|
38
|
+
const result = await client.updateVault(vaultId, body);
|
|
39
|
+
format(result, tableMode);
|
|
40
|
+
}
|
|
41
|
+
export async function handleVaultDelete(client, vaultId, confirmed) {
|
|
42
|
+
if (!confirmed) {
|
|
43
|
+
process.stderr.write(JSON.stringify({ error: { code: 'confirm_required', message: 'Pass --confirm to acknowledge this is a hard delete with no undo.' } }) + '\n');
|
|
44
|
+
process.exit(2);
|
|
45
|
+
}
|
|
46
|
+
const result = await client.deleteVault(vaultId);
|
|
47
|
+
format(result, false);
|
|
48
|
+
}
|
|
49
|
+
export async function handleVaultVisibility(client, vaultId, opts, tableMode) {
|
|
50
|
+
const body = { visibility: opts.visibility };
|
|
51
|
+
if (opts.slug)
|
|
52
|
+
body.public_slug = opts.slug;
|
|
53
|
+
const result = await client.setVaultVisibility(vaultId, body);
|
|
54
|
+
format(result, tableMode);
|
|
55
|
+
}
|
|
56
|
+
export async function handleSharesList(client, vaultId, tableMode) {
|
|
57
|
+
const result = await client.listShares(vaultId);
|
|
58
|
+
format(result, tableMode, ['id', 'email', 'role', 'name']);
|
|
59
|
+
}
|
|
60
|
+
export async function handleShareAdd(client, vaultId, opts, tableMode) {
|
|
61
|
+
const result = await client.addShare(vaultId, opts);
|
|
62
|
+
format(result, tableMode);
|
|
63
|
+
}
|
|
64
|
+
export async function handleShareUpdate(client, vaultId, shareId, role, tableMode) {
|
|
65
|
+
const result = await client.updateShare(vaultId, shareId, { role });
|
|
66
|
+
format(result, tableMode);
|
|
67
|
+
}
|
|
68
|
+
export async function handleShareRemove(client, vaultId, shareId) {
|
|
69
|
+
const result = await client.removeShare(vaultId, shareId);
|
|
70
|
+
format(result, false);
|
|
71
|
+
}
|
|
72
|
+
export function registerVaults(program) {
|
|
73
|
+
const vaults = program.command('vaults').description('Manage vaults');
|
|
74
|
+
vaults
|
|
75
|
+
.command('list')
|
|
76
|
+
.description('List all accessible vaults')
|
|
77
|
+
.action(async (opts, cmd) => {
|
|
78
|
+
const g = cmd.optsWithGlobals();
|
|
79
|
+
const client = resolveClient(g.apiKey);
|
|
80
|
+
await run(() => handleVaultsList(client, g.table ?? false));
|
|
81
|
+
});
|
|
82
|
+
vaults
|
|
83
|
+
.command('get')
|
|
84
|
+
.argument('<vaultId>')
|
|
85
|
+
.description('Read one vault with full contents')
|
|
86
|
+
.action(async (vaultId, opts, cmd) => {
|
|
87
|
+
const g = cmd.optsWithGlobals();
|
|
88
|
+
const client = resolveClient(g.apiKey);
|
|
89
|
+
await run(() => handleVaultGet(client, vaultId, g.table ?? false));
|
|
90
|
+
});
|
|
91
|
+
vaults
|
|
92
|
+
.command('create')
|
|
93
|
+
.description('Create a vault')
|
|
94
|
+
.requiredOption('--name <name>', 'vault name')
|
|
95
|
+
.option('--description <desc>')
|
|
96
|
+
.option('--color <color>')
|
|
97
|
+
.option('--visibility <visibility>', 'private|protected|public')
|
|
98
|
+
.option('--category <category>')
|
|
99
|
+
.option('--abstract <abstract>')
|
|
100
|
+
.action(async (opts, cmd) => {
|
|
101
|
+
const g = cmd.optsWithGlobals();
|
|
102
|
+
const client = resolveClient(g.apiKey);
|
|
103
|
+
await run(() => handleVaultCreate(client, opts, g.table ?? false));
|
|
104
|
+
});
|
|
105
|
+
vaults
|
|
106
|
+
.command('update')
|
|
107
|
+
.argument('<vaultId>')
|
|
108
|
+
.description('Update vault metadata')
|
|
109
|
+
.option('--name <name>')
|
|
110
|
+
.option('--description <desc>')
|
|
111
|
+
.option('--color <color>')
|
|
112
|
+
.option('--category <category>')
|
|
113
|
+
.option('--abstract <abstract>')
|
|
114
|
+
.action(async (vaultId, opts, cmd) => {
|
|
115
|
+
const g = cmd.optsWithGlobals();
|
|
116
|
+
const client = resolveClient(g.apiKey);
|
|
117
|
+
await run(() => handleVaultUpdate(client, vaultId, opts, g.table ?? false));
|
|
118
|
+
});
|
|
119
|
+
vaults
|
|
120
|
+
.command('delete')
|
|
121
|
+
.argument('<vaultId>')
|
|
122
|
+
.description('Delete a vault (hard delete, no undo)')
|
|
123
|
+
.option('--confirm', 'required: acknowledge this is a permanent deletion')
|
|
124
|
+
.action(async (vaultId, opts, cmd) => {
|
|
125
|
+
const g = cmd.optsWithGlobals();
|
|
126
|
+
const client = resolveClient(g.apiKey);
|
|
127
|
+
await run(() => handleVaultDelete(client, vaultId, opts.confirm ?? false));
|
|
128
|
+
});
|
|
129
|
+
vaults
|
|
130
|
+
.command('visibility')
|
|
131
|
+
.argument('<vaultId>')
|
|
132
|
+
.description('Set vault visibility')
|
|
133
|
+
.requiredOption('--visibility <visibility>', 'private|protected|public')
|
|
134
|
+
.option('--slug <slug>', 'public_slug for public vaults')
|
|
135
|
+
.action(async (vaultId, opts, cmd) => {
|
|
136
|
+
const g = cmd.optsWithGlobals();
|
|
137
|
+
const client = resolveClient(g.apiKey);
|
|
138
|
+
await run(() => handleVaultVisibility(client, vaultId, { visibility: opts.visibility, slug: opts.slug }, g.table ?? false));
|
|
139
|
+
});
|
|
140
|
+
const shares = vaults.command('shares').description('Manage vault collaborators');
|
|
141
|
+
shares
|
|
142
|
+
.command('list')
|
|
143
|
+
.argument('<vaultId>')
|
|
144
|
+
.description('List vault collaborators')
|
|
145
|
+
.action(async (vaultId, opts, cmd) => {
|
|
146
|
+
const g = cmd.optsWithGlobals();
|
|
147
|
+
const client = resolveClient(g.apiKey);
|
|
148
|
+
await run(() => handleSharesList(client, vaultId, g.table ?? false));
|
|
149
|
+
});
|
|
150
|
+
shares
|
|
151
|
+
.command('add')
|
|
152
|
+
.argument('<vaultId>')
|
|
153
|
+
.description('Add a collaborator')
|
|
154
|
+
.requiredOption('--email <email>')
|
|
155
|
+
.requiredOption('--role <role>', 'viewer|editor')
|
|
156
|
+
.option('--name <name>')
|
|
157
|
+
.action(async (vaultId, opts, cmd) => {
|
|
158
|
+
const g = cmd.optsWithGlobals();
|
|
159
|
+
const client = resolveClient(g.apiKey);
|
|
160
|
+
await run(() => handleShareAdd(client, vaultId, { email: opts.email, role: opts.role, name: opts.name }, g.table ?? false));
|
|
161
|
+
});
|
|
162
|
+
shares
|
|
163
|
+
.command('update')
|
|
164
|
+
.argument('<vaultId>')
|
|
165
|
+
.argument('<shareId>')
|
|
166
|
+
.description('Update a collaborator role')
|
|
167
|
+
.requiredOption('--role <role>', 'viewer|editor')
|
|
168
|
+
.action(async (vaultId, shareId, opts, cmd) => {
|
|
169
|
+
const g = cmd.optsWithGlobals();
|
|
170
|
+
const client = resolveClient(g.apiKey);
|
|
171
|
+
await run(() => handleShareUpdate(client, vaultId, shareId, opts.role, g.table ?? false));
|
|
172
|
+
});
|
|
173
|
+
shares
|
|
174
|
+
.command('remove')
|
|
175
|
+
.argument('<vaultId>')
|
|
176
|
+
.argument('<shareId>')
|
|
177
|
+
.description('Remove a collaborator')
|
|
178
|
+
.action(async (vaultId, shareId, opts, cmd) => {
|
|
179
|
+
const g = cmd.optsWithGlobals();
|
|
180
|
+
const client = resolveClient(g.apiKey);
|
|
181
|
+
await run(() => handleShareRemove(client, vaultId, shareId));
|
|
182
|
+
});
|
|
183
|
+
}
|
package/dist/format.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function format(response: unknown, tableMode: boolean, columns?: string[]): void;
|
package/dist/format.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// src/format.ts
|
|
2
|
+
import Table from 'cli-table3';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
export function format(response, tableMode, columns) {
|
|
5
|
+
if (!tableMode) {
|
|
6
|
+
process.stdout.write(JSON.stringify(response, null, 2) + '\n');
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
const data = response?.data;
|
|
10
|
+
if (!Array.isArray(data) || data.length === 0) {
|
|
11
|
+
process.stdout.write(JSON.stringify(response, null, 2) + '\n');
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const cols = columns ?? Object.keys(data[0]);
|
|
15
|
+
const table = new Table({
|
|
16
|
+
head: cols.map((c) => chalk.cyan(c)),
|
|
17
|
+
});
|
|
18
|
+
for (const row of data) {
|
|
19
|
+
table.push(cols.map((c) => String(row[c] ?? '')));
|
|
20
|
+
}
|
|
21
|
+
process.stdout.write(table.toString() + '\n');
|
|
22
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// src/index.ts
|
|
3
|
+
import { Command } from 'commander';
|
|
4
|
+
import { registerVaults } from './commands/vaults.js';
|
|
5
|
+
import { registerItems } from './commands/items.js';
|
|
6
|
+
import { registerTags } from './commands/tags.js';
|
|
7
|
+
import { registerRelations } from './commands/relations.js';
|
|
8
|
+
import { registerImport } from './commands/import.js';
|
|
9
|
+
import { registerExport } from './commands/export.js';
|
|
10
|
+
import { registerAudit } from './commands/audit.js';
|
|
11
|
+
const program = new Command();
|
|
12
|
+
program
|
|
13
|
+
.name('refhub')
|
|
14
|
+
.description('RefHub CLI — manage vaults, items, tags, and relations')
|
|
15
|
+
.version('0.1.0')
|
|
16
|
+
.option('--api-key <key>', 'RefHub API key (overrides REFHUB_API_KEY env var)')
|
|
17
|
+
.option('--table', 'human-readable table output (default: JSON)');
|
|
18
|
+
registerVaults(program);
|
|
19
|
+
registerItems(program);
|
|
20
|
+
registerTags(program);
|
|
21
|
+
registerRelations(program);
|
|
22
|
+
registerImport(program);
|
|
23
|
+
registerExport(program);
|
|
24
|
+
registerAudit(program);
|
|
25
|
+
program.parseAsync();
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
export type RelationType = 'cites' | 'extends' | 'builds_on' | 'contradicts' | 'reviews' | 'related';
|
|
2
|
+
export interface Vault {
|
|
3
|
+
id: string;
|
|
4
|
+
name: string;
|
|
5
|
+
description?: string;
|
|
6
|
+
color?: string;
|
|
7
|
+
visibility: 'private' | 'protected' | 'public';
|
|
8
|
+
category?: string;
|
|
9
|
+
abstract?: string;
|
|
10
|
+
public_slug?: string;
|
|
11
|
+
item_count: number;
|
|
12
|
+
created_at: string;
|
|
13
|
+
updated_at: string;
|
|
14
|
+
}
|
|
15
|
+
export interface Item {
|
|
16
|
+
id: string;
|
|
17
|
+
vault_id: string;
|
|
18
|
+
original_publication_id: string;
|
|
19
|
+
title: string;
|
|
20
|
+
authors?: string[];
|
|
21
|
+
year?: number;
|
|
22
|
+
doi?: string;
|
|
23
|
+
bibtex_key?: string;
|
|
24
|
+
abstract?: string;
|
|
25
|
+
tag_ids: string[];
|
|
26
|
+
version: number;
|
|
27
|
+
created_at: string;
|
|
28
|
+
updated_at: string;
|
|
29
|
+
}
|
|
30
|
+
export interface Tag {
|
|
31
|
+
id: string;
|
|
32
|
+
vault_id: string;
|
|
33
|
+
name: string;
|
|
34
|
+
color?: string;
|
|
35
|
+
parent_id?: string;
|
|
36
|
+
created_at: string;
|
|
37
|
+
updated_at: string;
|
|
38
|
+
}
|
|
39
|
+
export interface Relation {
|
|
40
|
+
id: string;
|
|
41
|
+
vault_id: string;
|
|
42
|
+
publication_id: string;
|
|
43
|
+
related_publication_id: string;
|
|
44
|
+
relation_type: RelationType;
|
|
45
|
+
created_at: string;
|
|
46
|
+
updated_at: string;
|
|
47
|
+
}
|
|
48
|
+
export interface Share {
|
|
49
|
+
id: string;
|
|
50
|
+
vault_id: string;
|
|
51
|
+
email: string;
|
|
52
|
+
role: 'viewer' | 'editor';
|
|
53
|
+
name?: string;
|
|
54
|
+
created_at: string;
|
|
55
|
+
}
|
|
56
|
+
export interface VaultDetail extends Vault {
|
|
57
|
+
items: Item[];
|
|
58
|
+
tags: Tag[];
|
|
59
|
+
relations: Relation[];
|
|
60
|
+
}
|
|
61
|
+
export interface VaultStats {
|
|
62
|
+
item_count: number;
|
|
63
|
+
tag_count: number;
|
|
64
|
+
relation_count: number;
|
|
65
|
+
last_updated: string;
|
|
66
|
+
}
|
|
67
|
+
export interface UpsertResult {
|
|
68
|
+
created: Item[];
|
|
69
|
+
updated: Item[];
|
|
70
|
+
errors: Array<{
|
|
71
|
+
item: unknown;
|
|
72
|
+
error: string;
|
|
73
|
+
}>;
|
|
74
|
+
}
|
|
75
|
+
export interface PreviewResult {
|
|
76
|
+
would_create: Item[];
|
|
77
|
+
would_update: Item[];
|
|
78
|
+
invalid: Array<{
|
|
79
|
+
item: unknown;
|
|
80
|
+
error: string;
|
|
81
|
+
}>;
|
|
82
|
+
}
|
|
83
|
+
export interface BibTeXImportResult {
|
|
84
|
+
created: Item[];
|
|
85
|
+
skipped: string[];
|
|
86
|
+
}
|
|
87
|
+
export interface AuditEntry {
|
|
88
|
+
id: string;
|
|
89
|
+
vault_id?: string;
|
|
90
|
+
action: string;
|
|
91
|
+
entity_type: string;
|
|
92
|
+
entity_id: string;
|
|
93
|
+
actor_id: string;
|
|
94
|
+
metadata?: Record<string, unknown>;
|
|
95
|
+
created_at: string;
|
|
96
|
+
}
|
|
97
|
+
export interface ApiResponse<T> {
|
|
98
|
+
data: T;
|
|
99
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@refhub/cli",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "refhub CLI execution layer for agent skills",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"engines": { "node": ">=18" },
|
|
7
|
+
"bin": { "refhub": "dist/index.js" },
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc && node -e \"import('fs').then(fs=>{ const f='dist/index.js'; fs.writeFileSync(f,'#!/usr/bin/env node\\n'+fs.readFileSync(f,'utf8')); fs.chmodSync(f,'755'); })\"",
|
|
10
|
+
"test": "vitest run",
|
|
11
|
+
"test:watch": "vitest",
|
|
12
|
+
"smoke": "tsx scripts/smoke.ts",
|
|
13
|
+
"dev": "tsx src/index.ts"
|
|
14
|
+
},
|
|
15
|
+
"files": ["dist"],
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"chalk": "^5.3.0",
|
|
21
|
+
"cli-table3": "^0.6.5",
|
|
22
|
+
"commander": "^12.0.0"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@types/node": "^20.0.0",
|
|
26
|
+
"tsx": "^4.7.0",
|
|
27
|
+
"typescript": "^5.4.0",
|
|
28
|
+
"vitest": "^1.6.0"
|
|
29
|
+
}
|
|
30
|
+
}
|