summd 0.1.2 → 0.1.4
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/dist/api.js +11 -2
- package/dist/index.js +28 -5
- package/package.json +11 -4
package/dist/api.js
CHANGED
|
@@ -26,8 +26,17 @@ function text(result) {
|
|
|
26
26
|
return result.content.map(c => c.text).join('');
|
|
27
27
|
}
|
|
28
28
|
// ── Public API ────────────────────────────────────────────────────────────────
|
|
29
|
-
export async function add(content, tags, opts) {
|
|
30
|
-
|
|
29
|
+
export async function add(content, tags, opts, note) {
|
|
30
|
+
const args = { content, tags, source_type: 'cli' };
|
|
31
|
+
if (note)
|
|
32
|
+
args.note = note;
|
|
33
|
+
return text(await tool('add_entry', args, opts));
|
|
34
|
+
}
|
|
35
|
+
export async function addUrl(url, tags, opts, note) {
|
|
36
|
+
const args = { url, tags, source_type: 'cli' };
|
|
37
|
+
if (note)
|
|
38
|
+
args.note = note;
|
|
39
|
+
return text(await tool('add_entry', args, opts));
|
|
31
40
|
}
|
|
32
41
|
export async function search(query, limit, opts) {
|
|
33
42
|
return text(await tool('search_context', { query, limit }, opts));
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,23 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { readFileSync } from 'fs';
|
|
3
|
+
import { extname } from 'path';
|
|
3
4
|
import { createInterface } from 'readline';
|
|
4
5
|
import { program } from 'commander';
|
|
5
6
|
import { saveKey } from './config.js';
|
|
6
7
|
import * as api from './api.js';
|
|
8
|
+
const CODE_EXTS = new Set([
|
|
9
|
+
'js', 'ts', 'jsx', 'tsx', 'mjs', 'cjs',
|
|
10
|
+
'py', 'rb', 'go', 'rs', 'java', 'kt', 'swift', 'c', 'cpp', 'cs',
|
|
11
|
+
'sh', 'bash', 'zsh', 'fish',
|
|
12
|
+
'json', 'yaml', 'yml', 'toml', 'xml',
|
|
13
|
+
'sql', 'graphql', 'html', 'css', 'scss',
|
|
14
|
+
]);
|
|
15
|
+
function wrapIfCode(content, filePath) {
|
|
16
|
+
const ext = extname(filePath).slice(1).toLowerCase();
|
|
17
|
+
if (!CODE_EXTS.has(ext))
|
|
18
|
+
return content;
|
|
19
|
+
return `\`\`\`${ext}\n${content}\n\`\`\``;
|
|
20
|
+
}
|
|
7
21
|
// ── helpers ───────────────────────────────────────────────────────────────────
|
|
8
22
|
function globalOpts() {
|
|
9
23
|
return program.opts();
|
|
@@ -32,7 +46,7 @@ function formatDate(iso) {
|
|
|
32
46
|
program
|
|
33
47
|
.name('summd')
|
|
34
48
|
.description('Sum to anything.')
|
|
35
|
-
.version('0.1.
|
|
49
|
+
.version('0.1.3')
|
|
36
50
|
.option('--key <token>', 'API key for this request')
|
|
37
51
|
.option('--base <url>', 'Override API base URL');
|
|
38
52
|
// ── summd key ─────────────────────────────────────────────────────────────────
|
|
@@ -49,18 +63,27 @@ program
|
|
|
49
63
|
.description('Add an entry — reads stdin if no content given')
|
|
50
64
|
.option('-t, --tag <tags>', 'Comma-separated tags')
|
|
51
65
|
.option('-f, --file <path>', 'Read content from file')
|
|
66
|
+
.option('-u, --url <url>', 'Fetch URL and save as entry (articles, YouTube, etc.)')
|
|
67
|
+
.option('-n, --note <text>', 'Personal annotation (not included in AI summarization)')
|
|
52
68
|
.action(async (content, cmd) => {
|
|
53
69
|
const tags = cmd.tag ? cmd.tag.split(',').map(t => t.trim()) : [];
|
|
70
|
+
// URL mode: delegate fetch + convert to server
|
|
71
|
+
if (cmd.url) {
|
|
72
|
+
console.log(await api.addUrl(cmd.url, tags, globalOpts(), cmd.note));
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
54
75
|
let body = content;
|
|
55
|
-
if (!body && cmd.file)
|
|
56
|
-
|
|
76
|
+
if (!body && cmd.file) {
|
|
77
|
+
const raw = readFileSync(cmd.file, 'utf8');
|
|
78
|
+
body = wrapIfCode(raw, cmd.file);
|
|
79
|
+
}
|
|
57
80
|
if (!body && !process.stdin.isTTY)
|
|
58
81
|
body = await readStdin();
|
|
59
82
|
if (!body) {
|
|
60
|
-
console.error('Provide content, --file, or pipe from stdin.');
|
|
83
|
+
console.error('Provide content, --file, --url, or pipe from stdin.');
|
|
61
84
|
process.exit(1);
|
|
62
85
|
}
|
|
63
|
-
console.log(await api.add(body, tags, globalOpts()));
|
|
86
|
+
console.log(await api.add(body, tags, globalOpts(), cmd.note));
|
|
64
87
|
});
|
|
65
88
|
// ── summd search ──────────────────────────────────────────────────────────────
|
|
66
89
|
program
|
package/package.json
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "summd",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "CLI for sum.md — Sum to anything.",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"bin": {
|
|
6
|
+
"bin": {
|
|
7
|
+
"summd": "./dist/index.js"
|
|
8
|
+
},
|
|
7
9
|
"type": "module",
|
|
8
|
-
"files": [
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"README.md"
|
|
13
|
+
],
|
|
9
14
|
"scripts": {
|
|
10
15
|
"build": "tsc",
|
|
11
16
|
"dev": "tsc --watch",
|
|
@@ -18,5 +23,7 @@
|
|
|
18
23
|
"@types/node": "^20.0.0",
|
|
19
24
|
"typescript": "^5.0.0"
|
|
20
25
|
},
|
|
21
|
-
"engines": {
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=18"
|
|
28
|
+
}
|
|
22
29
|
}
|