@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.
@@ -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 parseCreatePostRequest(input) {
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) ? input.tags.filter((tag) => typeof tag === 'string') : [];
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' || input.sourceType === 'imported' || input.sourceType === 'skill_command'
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' ? 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 parsePostMutationRequest(input) {
41
+ function parseNoteMutationRequest(input) {
36
42
  const requestId = typeof input.requestId === 'string' ? input.requestId : randomUUID();
37
- const postId = typeof input.postId === 'string' ? input.postId.trim() : '';
38
- if (!postId) {
39
- throw new Error('postId is required.');
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
- postId,
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
- createPost(input) {
91
- return this.request('/integrations/posts', 'POST', parseCreatePostRequest(input));
96
+ createNote(input) {
97
+ return this.request('/integrations/notes', 'POST', parseCreateNoteRequest(input));
92
98
  }
93
- deletePost(input) {
94
- const body = parsePostMutationRequest(input);
95
- return this.request(`/integrations/posts/${body.postId}/delete`, 'POST', body);
99
+ deleteNote(input) {
100
+ const body = parseNoteMutationRequest(input);
101
+ return this.request(`/integrations/notes/${body.noteId}/delete`, 'POST', body);
96
102
  }
97
- restorePost(input) {
98
- const body = parsePostMutationRequest(input);
99
- return this.request(`/integrations/posts/${body.postId}/restore`, 'POST', body);
103
+ restoreNote(input) {
104
+ const body = parseNoteMutationRequest(input);
105
+ return this.request(`/integrations/notes/${body.noteId}/restore`, 'POST', body);
100
106
  }
101
- permanentDeletePost(input) {
102
- const body = parsePostMutationRequest(input);
103
- return this.request(`/integrations/posts/${body.postId}/permanent-delete`, 'POST', body);
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
- listPosts(input) {
76
- return this.request(this.buildPath('/posts/me', input));
75
+ listNotes(input) {
76
+ return this.request(this.buildPath('/notes/me', input));
77
77
  }
78
- searchPosts(query) {
79
- return this.request(this.buildPath('/posts/me/search', { q: query }));
78
+ searchNotes(query) {
79
+ return this.request(this.buildPath('/notes/me/search', { q: query }));
80
80
  }
81
- listStarredPosts(input) {
82
- return this.request(this.buildPath('/posts/me/starred', input));
81
+ listStarredNotes(input) {
82
+ return this.request(this.buildPath('/notes/me/starred', input));
83
83
  }
84
- listDeletedPosts(input) {
85
- return this.request(this.buildPath('/posts/me/deleted', input));
84
+ listDeletedNotes(input) {
85
+ return this.request(this.buildPath('/notes/me/deleted', input));
86
86
  }
87
- getPost(id) {
88
- return this.request(`/posts/${id}`);
87
+ getNote(id) {
88
+ return this.request(`/notes/${id}`);
89
89
  }
90
- updatePost(id, input) {
91
- return this.request(`/posts/${id}/content`, {
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(`/posts/${id}/star`, {
97
+ return this.request(`/notes/${id}/star`, {
98
98
  method: 'PATCH',
99
99
  });
100
100
  }
101
101
  togglePin(id) {
102
- return this.request(`/posts/${id}/pin`, {
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 getPostApiClient(config) {
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 executePostAction(config, input) {
24
- const { client, error } = getPostApiClient(config);
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.createPost({
29
+ const response = await client.createNote({
30
30
  requestId: randomUUID(),
31
31
  requestedAt: new Date().toISOString(),
32
- traceId: `${input.traceIdPrefix ?? 'post'}-${Date.now()}`,
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: `Post published. Post id ${String(response.data.id)} is now visible in the feed.`,
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
- postId: String(response.data.id),
50
+ noteId: String(response.data.id),
51
51
  };
52
52
  }
53
53
  if (input.action === 'delete') {
54
- const response = await client.deletePost({
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
- postId: input.postId,
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: 'Post deleted. The current post is no longer visible in the feed.',
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
- postId: null,
71
+ noteId: null,
72
72
  };
73
73
  }
74
74
  if (input.action === 'restore') {
75
- const response = await client.restorePost({
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
- postId: input.postId,
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: `Post restored. Post id ${input.postId} is now back in the feed.`,
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
- postId: input.postId,
92
+ noteId: input.noteId,
93
93
  };
94
94
  }
95
- const response = await client.permanentDeletePost({
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
- postId: input.postId,
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: `Post permanently deleted. Post id ${input.postId} has been removed from the database.`,
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
- postId: null,
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 getPostPreview(post) {
27
- const content = (post.title?.trim() || post.finalText?.trim() || post.rawText?.trim() || '').replace(/\s+/g, ' ');
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(post) {
36
+ function getStatusFlags(note) {
34
37
  const flags = [];
35
- if (post.isPinned) {
38
+ if (note.isPinned) {
36
39
  flags.push('pinned');
37
40
  }
38
- if (post.isStarred) {
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 formatPostCollection(title, posts) {
46
+ export function formatNoteCollection(title, notes) {
44
47
  const lines = [title, ''];
45
- if (posts.length === 0) {
46
- lines.push('No posts found.');
48
+ if (notes.length === 0) {
49
+ lines.push('No notes found.');
47
50
  return lines.join('\n');
48
51
  }
49
- for (const post of posts) {
50
- lines.push(`${post.id} ${formatTimestamp(post.updatedAt ?? post.createdAt)}`);
51
- lines.push(` flags: ${getStatusFlags(post)} visibility: ${post.visibility} tags: ${formatTags(post.tags, 3)}`);
52
- lines.push(` ${getPostPreview(post)}`);
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 formatPostDetail(post) {
58
- const title = post.title?.trim() || '(untitled)';
59
- const body = post.finalText?.trim() || post.rawText?.trim() || '(empty)';
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: ${post.id}`,
66
- `visibility: ${post.visibility}`,
67
- `created: ${formatTimestamp(post.createdAt)}`,
68
- `updated: ${formatTimestamp(post.updatedAt)}`,
69
- `tags: ${formatTags(post.tags)}`,
70
- `folder: ${post.folder ? `${post.folder.name} (${post.folder.id})` : 'none'}`,
71
- `pinned: ${post.isPinned ? 'yes' : 'no'}`,
72
- `starred: ${post.isStarred ? 'yes' : 'no'}`,
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.7",
4
- "description": "Kiipu CLI for local authentication, doctor checks, and direct post actions.",
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": {