@kiipu/cli 0.0.7 → 0.0.9
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 +50 -20
- package/dist/commands/ask.js +229 -0
- package/dist/commands/auth.js +1 -1
- package/dist/commands/doctor.js +9 -3
- package/dist/commands/help.js +85 -48
- package/dist/commands/{post.js → note.js} +68 -64
- package/dist/config/load-env.js +4 -1
- package/dist/index.js +17 -4
- package/dist/lib/ask-client.js +278 -0
- package/dist/lib/ask-formatters.js +114 -0
- package/dist/lib/kiipu-integration-client.js +26 -20
- package/dist/lib/kiipu-user-client.js +14 -14
- package/dist/lib/{post-actions.js → note-actions.js} +19 -19
- package/dist/lib/{post-formatters.js → note-formatters.js} +26 -23
- package/package.json +2 -2
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
function formatTimestamp(value) {
|
|
2
|
+
if (!value) {
|
|
3
|
+
return 'unknown time';
|
|
4
|
+
}
|
|
5
|
+
const parsed = new Date(value);
|
|
6
|
+
if (Number.isNaN(parsed.getTime())) {
|
|
7
|
+
return value;
|
|
8
|
+
}
|
|
9
|
+
return parsed.toLocaleString('en-US', {
|
|
10
|
+
year: 'numeric',
|
|
11
|
+
month: 'short',
|
|
12
|
+
day: '2-digit',
|
|
13
|
+
hour: '2-digit',
|
|
14
|
+
minute: '2-digit',
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
function truncate(value, maxLength) {
|
|
18
|
+
const normalized = value.trim().replace(/\s+/g, ' ');
|
|
19
|
+
if (normalized.length <= maxLength) {
|
|
20
|
+
return normalized;
|
|
21
|
+
}
|
|
22
|
+
return `${normalized.slice(0, maxLength - 3)}...`;
|
|
23
|
+
}
|
|
24
|
+
function formatSourceLine(source) {
|
|
25
|
+
const title = source.title?.trim() || '(untitled)';
|
|
26
|
+
const score = Number.isFinite(source.score) ? ` score ${source.score.toFixed(3)}` : '';
|
|
27
|
+
return `[${source.index}] ${title} (${source.noteId})${score}`;
|
|
28
|
+
}
|
|
29
|
+
export function formatAskFooter(input) {
|
|
30
|
+
const lines = ['', 'Sources:'];
|
|
31
|
+
if (input.sources.length === 0) {
|
|
32
|
+
lines.push(' none');
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
for (const source of input.sources) {
|
|
36
|
+
lines.push(` ${formatSourceLine(source)}`);
|
|
37
|
+
lines.push(` ${truncate(source.snippet, 140)}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const usage = input.usage;
|
|
41
|
+
if (usage) {
|
|
42
|
+
lines.push('', `Usage: input ${usage.inputTokens}, output ${usage.outputTokens}, latency ${usage.latencyMs}ms`);
|
|
43
|
+
}
|
|
44
|
+
if (input.conversationId) {
|
|
45
|
+
lines.push(`Conversation: ${input.conversationId}`);
|
|
46
|
+
}
|
|
47
|
+
if (input.title) {
|
|
48
|
+
lines.push(`Title: ${input.title}`);
|
|
49
|
+
}
|
|
50
|
+
if (input.turnId) {
|
|
51
|
+
lines.push(`Turn: ${input.turnId}`);
|
|
52
|
+
}
|
|
53
|
+
return lines.join('\n');
|
|
54
|
+
}
|
|
55
|
+
export function formatConversationHistory(title, conversations, nextCursor) {
|
|
56
|
+
const lines = [title, ''];
|
|
57
|
+
if (conversations.length === 0) {
|
|
58
|
+
lines.push('No Ask conversations found.');
|
|
59
|
+
return lines.join('\n');
|
|
60
|
+
}
|
|
61
|
+
for (const item of conversations) {
|
|
62
|
+
const label = item.title?.trim() || truncate(item.preview, 80) || '(untitled)';
|
|
63
|
+
const flags = [item.pinnedAt ? 'pinned' : '', item.archivedAt ? 'archived' : '']
|
|
64
|
+
.filter(Boolean)
|
|
65
|
+
.join(', ');
|
|
66
|
+
lines.push(`${item.id} ${formatTimestamp(item.lastMessageAt)}`);
|
|
67
|
+
lines.push(` ${label}`);
|
|
68
|
+
if (flags) {
|
|
69
|
+
lines.push(` flags: ${flags}`);
|
|
70
|
+
}
|
|
71
|
+
lines.push('');
|
|
72
|
+
}
|
|
73
|
+
if (nextCursor) {
|
|
74
|
+
lines.push(`Next cursor: ${nextCursor}`);
|
|
75
|
+
}
|
|
76
|
+
if (!nextCursor && lines[lines.length - 1] === '') {
|
|
77
|
+
lines.pop();
|
|
78
|
+
}
|
|
79
|
+
return lines.join('\n');
|
|
80
|
+
}
|
|
81
|
+
function formatTurn(turn) {
|
|
82
|
+
const role = turn.role === 'user' ? 'User' : 'Assistant';
|
|
83
|
+
const lines = [`${role} ${turn.id} ${formatTimestamp(turn.createdAt)} status: ${turn.status}`];
|
|
84
|
+
if (turn.errorCode) {
|
|
85
|
+
lines.push(`error: ${turn.errorCode}`);
|
|
86
|
+
}
|
|
87
|
+
lines.push(turn.content.trim() || '(empty)');
|
|
88
|
+
if (turn.sources && turn.sources.length > 0) {
|
|
89
|
+
lines.push('sources:');
|
|
90
|
+
for (const source of turn.sources) {
|
|
91
|
+
lines.push(` ${formatSourceLine(source)}`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return lines.join('\n');
|
|
95
|
+
}
|
|
96
|
+
export function formatConversationDetail(detail) {
|
|
97
|
+
const lines = [
|
|
98
|
+
detail.title?.trim() || '(untitled Ask conversation)',
|
|
99
|
+
'',
|
|
100
|
+
`id: ${detail.id}`,
|
|
101
|
+
`created: ${formatTimestamp(detail.createdAt)}`,
|
|
102
|
+
`updated: ${formatTimestamp(detail.lastMessageAt)}`,
|
|
103
|
+
'',
|
|
104
|
+
];
|
|
105
|
+
if (detail.turns.length === 0) {
|
|
106
|
+
lines.push('No turns found.');
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
for (const turn of detail.turns) {
|
|
110
|
+
lines.push(formatTurn(turn), '');
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return lines.slice(0, -1).join('\n');
|
|
114
|
+
}
|
|
@@ -9,40 +9,46 @@ function buildError(requestId, message, code = 'request_failed') {
|
|
|
9
9
|
},
|
|
10
10
|
};
|
|
11
11
|
}
|
|
12
|
-
function
|
|
12
|
+
function parseCreateNoteRequest(input) {
|
|
13
13
|
const requestId = typeof input.requestId === 'string' ? input.requestId : randomUUID();
|
|
14
14
|
const rawText = typeof input.rawText === 'string' ? input.rawText.trim() : '';
|
|
15
15
|
if (!rawText) {
|
|
16
16
|
throw new Error('rawText is required.');
|
|
17
17
|
}
|
|
18
18
|
const visibility = input.visibility;
|
|
19
|
-
const tags = Array.isArray(input.tags)
|
|
19
|
+
const tags = Array.isArray(input.tags)
|
|
20
|
+
? input.tags.filter((tag) => typeof tag === 'string')
|
|
21
|
+
: [];
|
|
20
22
|
return {
|
|
21
23
|
requestId,
|
|
22
24
|
requestedAt: typeof input.requestedAt === 'string' ? input.requestedAt : undefined,
|
|
23
25
|
traceId: typeof input.traceId === 'string' ? input.traceId : undefined,
|
|
24
26
|
rawText,
|
|
25
|
-
sourceType: input.sourceType === 'manual' ||
|
|
27
|
+
sourceType: input.sourceType === 'manual' ||
|
|
28
|
+
input.sourceType === 'imported' ||
|
|
29
|
+
input.sourceType === 'skill_command'
|
|
26
30
|
? input.sourceType
|
|
27
31
|
: 'skill_command',
|
|
28
32
|
finalText: typeof input.finalText === 'string' ? input.finalText : undefined,
|
|
29
|
-
visibility: visibility === 'unlisted' || visibility === 'private' || visibility === 'public'
|
|
33
|
+
visibility: visibility === 'unlisted' || visibility === 'private' || visibility === 'public'
|
|
34
|
+
? visibility
|
|
35
|
+
: 'public',
|
|
30
36
|
sourceMessageId: typeof input.sourceMessageId === 'string' ? input.sourceMessageId : undefined,
|
|
31
37
|
title: typeof input.title === 'string' ? input.title : input.title === null ? null : undefined,
|
|
32
38
|
tags,
|
|
33
39
|
};
|
|
34
40
|
}
|
|
35
|
-
function
|
|
41
|
+
function parseNoteMutationRequest(input) {
|
|
36
42
|
const requestId = typeof input.requestId === 'string' ? input.requestId : randomUUID();
|
|
37
|
-
const
|
|
38
|
-
if (!
|
|
39
|
-
throw new Error('
|
|
43
|
+
const noteId = typeof input.noteId === 'string' ? input.noteId.trim() : '';
|
|
44
|
+
if (!noteId) {
|
|
45
|
+
throw new Error('noteId is required.');
|
|
40
46
|
}
|
|
41
47
|
return {
|
|
42
48
|
requestId,
|
|
43
49
|
requestedAt: typeof input.requestedAt === 'string' ? input.requestedAt : undefined,
|
|
44
50
|
traceId: typeof input.traceId === 'string' ? input.traceId : undefined,
|
|
45
|
-
|
|
51
|
+
noteId,
|
|
46
52
|
};
|
|
47
53
|
}
|
|
48
54
|
export class KiipuIntegrationApiClient {
|
|
@@ -87,19 +93,19 @@ export class KiipuIntegrationApiClient {
|
|
|
87
93
|
? payload.code
|
|
88
94
|
: 'request_failed');
|
|
89
95
|
}
|
|
90
|
-
|
|
91
|
-
return this.request('/integrations/
|
|
96
|
+
createNote(input) {
|
|
97
|
+
return this.request('/integrations/notes', 'POST', parseCreateNoteRequest(input));
|
|
92
98
|
}
|
|
93
|
-
|
|
94
|
-
const body =
|
|
95
|
-
return this.request(`/integrations/
|
|
99
|
+
deleteNote(input) {
|
|
100
|
+
const body = parseNoteMutationRequest(input);
|
|
101
|
+
return this.request(`/integrations/notes/${body.noteId}/delete`, 'POST', body);
|
|
96
102
|
}
|
|
97
|
-
|
|
98
|
-
const body =
|
|
99
|
-
return this.request(`/integrations/
|
|
103
|
+
restoreNote(input) {
|
|
104
|
+
const body = parseNoteMutationRequest(input);
|
|
105
|
+
return this.request(`/integrations/notes/${body.noteId}/restore`, 'POST', body);
|
|
100
106
|
}
|
|
101
|
-
|
|
102
|
-
const body =
|
|
103
|
-
return this.request(`/integrations/
|
|
107
|
+
permanentDeleteNote(input) {
|
|
108
|
+
const body = parseNoteMutationRequest(input);
|
|
109
|
+
return this.request(`/integrations/notes/${body.noteId}/permanent-delete`, 'POST', body);
|
|
104
110
|
}
|
|
105
111
|
}
|
|
@@ -72,34 +72,34 @@ export class KiipuUserApiClient {
|
|
|
72
72
|
body: JSON.stringify(input),
|
|
73
73
|
});
|
|
74
74
|
}
|
|
75
|
-
|
|
76
|
-
return this.request(this.buildPath('/
|
|
75
|
+
listNotes(input) {
|
|
76
|
+
return this.request(this.buildPath('/notes/me', input));
|
|
77
77
|
}
|
|
78
|
-
|
|
79
|
-
return this.request(this.buildPath('/
|
|
78
|
+
searchNotes(query) {
|
|
79
|
+
return this.request(this.buildPath('/notes/me/search', { q: query }));
|
|
80
80
|
}
|
|
81
|
-
|
|
82
|
-
return this.request(this.buildPath('/
|
|
81
|
+
listStarredNotes(input) {
|
|
82
|
+
return this.request(this.buildPath('/notes/me/starred', input));
|
|
83
83
|
}
|
|
84
|
-
|
|
85
|
-
return this.request(this.buildPath('/
|
|
84
|
+
listDeletedNotes(input) {
|
|
85
|
+
return this.request(this.buildPath('/notes/me/deleted', input));
|
|
86
86
|
}
|
|
87
|
-
|
|
88
|
-
return this.request(`/
|
|
87
|
+
getNote(id) {
|
|
88
|
+
return this.request(`/notes/${id}`);
|
|
89
89
|
}
|
|
90
|
-
|
|
91
|
-
return this.request(`/
|
|
90
|
+
updateNote(id, input) {
|
|
91
|
+
return this.request(`/notes/${id}/content`, {
|
|
92
92
|
method: 'PATCH',
|
|
93
93
|
body: JSON.stringify(input),
|
|
94
94
|
});
|
|
95
95
|
}
|
|
96
96
|
toggleStar(id) {
|
|
97
|
-
return this.request(`/
|
|
97
|
+
return this.request(`/notes/${id}/star`, {
|
|
98
98
|
method: 'PATCH',
|
|
99
99
|
});
|
|
100
100
|
}
|
|
101
101
|
togglePin(id) {
|
|
102
|
-
return this.request(`/
|
|
102
|
+
return this.request(`/notes/${id}/pin`, {
|
|
103
103
|
method: 'PATCH',
|
|
104
104
|
});
|
|
105
105
|
}
|
|
@@ -3,7 +3,7 @@ import { KiipuIntegrationApiClient } from './kiipu-integration-client.js';
|
|
|
3
3
|
function formatRequestFailed(message, code) {
|
|
4
4
|
return `Request failed: ${message} (${code}).`;
|
|
5
5
|
}
|
|
6
|
-
function
|
|
6
|
+
function getNoteApiClient(config) {
|
|
7
7
|
const apiKey = config.apiKey ?? process.env.KIIPU_API_KEY ?? '';
|
|
8
8
|
if (!apiKey) {
|
|
9
9
|
return {
|
|
@@ -20,16 +20,16 @@ function getPostApiClient(config) {
|
|
|
20
20
|
}),
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
|
-
export async function
|
|
24
|
-
const { client, error } =
|
|
23
|
+
export async function executeNoteAction(config, input) {
|
|
24
|
+
const { client, error } = getNoteApiClient(config);
|
|
25
25
|
if (!client) {
|
|
26
26
|
return error;
|
|
27
27
|
}
|
|
28
28
|
if (input.action === 'create') {
|
|
29
|
-
const response = await client.
|
|
29
|
+
const response = await client.createNote({
|
|
30
30
|
requestId: randomUUID(),
|
|
31
31
|
requestedAt: new Date().toISOString(),
|
|
32
|
-
traceId: `${input.traceIdPrefix ?? '
|
|
32
|
+
traceId: `${input.traceIdPrefix ?? 'note'}-${Date.now()}`,
|
|
33
33
|
rawText: input.content,
|
|
34
34
|
sourceType: 'skill_command',
|
|
35
35
|
sourceMessageId: input.sourceMessageId ?? `local-${Date.now()}`,
|
|
@@ -44,18 +44,18 @@ export async function executePostAction(config, input) {
|
|
|
44
44
|
}
|
|
45
45
|
return {
|
|
46
46
|
ok: true,
|
|
47
|
-
message: `
|
|
47
|
+
message: `Note created. Note id ${String(response.data.id)} is now visible in the feed.`,
|
|
48
48
|
data: response.data,
|
|
49
49
|
requestId: response.requestId,
|
|
50
|
-
|
|
50
|
+
noteId: String(response.data.id),
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
53
|
if (input.action === 'delete') {
|
|
54
|
-
const response = await client.
|
|
54
|
+
const response = await client.deleteNote({
|
|
55
55
|
requestId: randomUUID(),
|
|
56
56
|
requestedAt: new Date().toISOString(),
|
|
57
57
|
traceId: `${input.traceIdPrefix ?? 'delete'}-${Date.now()}`,
|
|
58
|
-
|
|
58
|
+
noteId: input.noteId,
|
|
59
59
|
});
|
|
60
60
|
if (!response.ok) {
|
|
61
61
|
return {
|
|
@@ -65,18 +65,18 @@ export async function executePostAction(config, input) {
|
|
|
65
65
|
}
|
|
66
66
|
return {
|
|
67
67
|
ok: true,
|
|
68
|
-
message: '
|
|
68
|
+
message: 'Note deleted. The current note is no longer visible in the feed.',
|
|
69
69
|
data: response.data,
|
|
70
70
|
requestId: response.requestId,
|
|
71
|
-
|
|
71
|
+
noteId: null,
|
|
72
72
|
};
|
|
73
73
|
}
|
|
74
74
|
if (input.action === 'restore') {
|
|
75
|
-
const response = await client.
|
|
75
|
+
const response = await client.restoreNote({
|
|
76
76
|
requestId: randomUUID(),
|
|
77
77
|
requestedAt: new Date().toISOString(),
|
|
78
78
|
traceId: `${input.traceIdPrefix ?? 'restore'}-${Date.now()}`,
|
|
79
|
-
|
|
79
|
+
noteId: input.noteId,
|
|
80
80
|
});
|
|
81
81
|
if (!response.ok) {
|
|
82
82
|
return {
|
|
@@ -86,17 +86,17 @@ export async function executePostAction(config, input) {
|
|
|
86
86
|
}
|
|
87
87
|
return {
|
|
88
88
|
ok: true,
|
|
89
|
-
message: `
|
|
89
|
+
message: `Note restored. Note id ${input.noteId} is now back in the feed.`,
|
|
90
90
|
data: response.data,
|
|
91
91
|
requestId: response.requestId,
|
|
92
|
-
|
|
92
|
+
noteId: input.noteId,
|
|
93
93
|
};
|
|
94
94
|
}
|
|
95
|
-
const response = await client.
|
|
95
|
+
const response = await client.permanentDeleteNote({
|
|
96
96
|
requestId: randomUUID(),
|
|
97
97
|
requestedAt: new Date().toISOString(),
|
|
98
98
|
traceId: `${input.traceIdPrefix ?? 'purge'}-${Date.now()}`,
|
|
99
|
-
|
|
99
|
+
noteId: input.noteId,
|
|
100
100
|
});
|
|
101
101
|
if (!response.ok) {
|
|
102
102
|
return {
|
|
@@ -106,9 +106,9 @@ export async function executePostAction(config, input) {
|
|
|
106
106
|
}
|
|
107
107
|
return {
|
|
108
108
|
ok: true,
|
|
109
|
-
message: `
|
|
109
|
+
message: `Note permanently deleted. Note id ${input.noteId} has been removed from the database.`,
|
|
110
110
|
data: response.data,
|
|
111
111
|
requestId: response.requestId,
|
|
112
|
-
|
|
112
|
+
noteId: null,
|
|
113
113
|
};
|
|
114
114
|
}
|
|
@@ -23,52 +23,55 @@ function formatTags(tags, limit) {
|
|
|
23
23
|
: [];
|
|
24
24
|
return normalized.length > 0 ? normalized.map((tag) => `#${tag}`).join(', ') : 'none';
|
|
25
25
|
}
|
|
26
|
-
function
|
|
27
|
-
const content = (
|
|
26
|
+
function getNotePreview(note) {
|
|
27
|
+
const content = (note.title?.trim() ||
|
|
28
|
+
note.finalText?.trim() ||
|
|
29
|
+
note.rawText?.trim() ||
|
|
30
|
+
'').replace(/\s+/g, ' ');
|
|
28
31
|
if (!content) {
|
|
29
32
|
return '(empty)';
|
|
30
33
|
}
|
|
31
34
|
return content.length > 100 ? `${content.slice(0, 97)}...` : content;
|
|
32
35
|
}
|
|
33
|
-
function getStatusFlags(
|
|
36
|
+
function getStatusFlags(note) {
|
|
34
37
|
const flags = [];
|
|
35
|
-
if (
|
|
38
|
+
if (note.isPinned) {
|
|
36
39
|
flags.push('pinned');
|
|
37
40
|
}
|
|
38
|
-
if (
|
|
41
|
+
if (note.isStarred) {
|
|
39
42
|
flags.push('starred');
|
|
40
43
|
}
|
|
41
44
|
return flags.length > 0 ? flags.join(', ') : 'none';
|
|
42
45
|
}
|
|
43
|
-
export function
|
|
46
|
+
export function formatNoteCollection(title, notes) {
|
|
44
47
|
const lines = [title, ''];
|
|
45
|
-
if (
|
|
46
|
-
lines.push('No
|
|
48
|
+
if (notes.length === 0) {
|
|
49
|
+
lines.push('No notes found.');
|
|
47
50
|
return lines.join('\n');
|
|
48
51
|
}
|
|
49
|
-
for (const
|
|
50
|
-
lines.push(`${
|
|
51
|
-
lines.push(` flags: ${getStatusFlags(
|
|
52
|
-
lines.push(` ${
|
|
52
|
+
for (const note of notes) {
|
|
53
|
+
lines.push(`${note.id} ${formatTimestamp(note.updatedAt ?? note.createdAt)}`);
|
|
54
|
+
lines.push(` flags: ${getStatusFlags(note)} visibility: ${note.visibility} tags: ${formatTags(note.tags, 3)}`);
|
|
55
|
+
lines.push(` ${getNotePreview(note)}`);
|
|
53
56
|
lines.push('');
|
|
54
57
|
}
|
|
55
58
|
return lines.slice(0, -1).join('\n');
|
|
56
59
|
}
|
|
57
|
-
export function
|
|
58
|
-
const title =
|
|
59
|
-
const body =
|
|
60
|
+
export function formatNoteDetail(note) {
|
|
61
|
+
const title = note.title?.trim() || '(untitled)';
|
|
62
|
+
const body = note.finalText?.trim() || note.rawText?.trim() || '(empty)';
|
|
60
63
|
return [
|
|
61
64
|
title,
|
|
62
65
|
'',
|
|
63
66
|
body,
|
|
64
67
|
'',
|
|
65
|
-
`id: ${
|
|
66
|
-
`visibility: ${
|
|
67
|
-
`created: ${formatTimestamp(
|
|
68
|
-
`updated: ${formatTimestamp(
|
|
69
|
-
`tags: ${formatTags(
|
|
70
|
-
`folder: ${
|
|
71
|
-
`pinned: ${
|
|
72
|
-
`starred: ${
|
|
68
|
+
`id: ${note.id}`,
|
|
69
|
+
`visibility: ${note.visibility}`,
|
|
70
|
+
`created: ${formatTimestamp(note.createdAt)}`,
|
|
71
|
+
`updated: ${formatTimestamp(note.updatedAt)}`,
|
|
72
|
+
`tags: ${formatTags(note.tags)}`,
|
|
73
|
+
`folder: ${note.folder ? `${note.folder.name} (${note.folder.id})` : 'none'}`,
|
|
74
|
+
`pinned: ${note.isPinned ? 'yes' : 'no'}`,
|
|
75
|
+
`starred: ${note.isStarred ? 'yes' : 'no'}`,
|
|
73
76
|
].join('\n');
|
|
74
77
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kiipu/cli",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "Kiipu CLI for local authentication, doctor checks, and direct
|
|
3
|
+
"version": "0.0.9",
|
|
4
|
+
"description": "Kiipu CLI for local authentication, doctor checks, and direct note actions.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"repository": {
|