@pinet/pinet-core 0.1.2 → 0.2.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.
@@ -1,10 +1,29 @@
1
1
  import { classifyPinetMail, formatPinetMailClassLabel, } from "@pinet/broker-core/mail-classification";
2
- function truncateText(value, maxLength = 180) {
2
+ const COMPACT_READ_DETAIL_LIMIT = 10;
3
+ const COMPACT_READ_TEXT_MESSAGE_LIMIT = 3;
4
+ const COMPACT_READ_PREVIEW_LENGTH = 96;
5
+ function truncateText(value, maxLength = COMPACT_READ_PREVIEW_LENGTH) {
3
6
  const collapsed = value.replace(/\s+/g, " ").trim();
4
7
  if (collapsed.length <= maxLength)
5
8
  return collapsed;
6
9
  return `${collapsed.slice(0, Math.max(0, maxLength - 1))}…`;
7
10
  }
11
+ function classifyReadMessage(item) {
12
+ return classifyPinetMail({
13
+ source: item.message.source,
14
+ threadId: item.message.threadId,
15
+ sender: item.message.sender,
16
+ body: item.message.body,
17
+ metadata: item.message.metadata,
18
+ }).class;
19
+ }
20
+ function formatCompactMessagePreview(item) {
21
+ const label = formatPinetMailClassLabel(classifyReadMessage(item));
22
+ return `- [${label}] [${item.message.source}/${item.message.threadId} #${item.message.id}] ${item.message.sender}: ${truncateText(item.message.body)}`;
23
+ }
24
+ function isMessageBodyTruncated(item) {
25
+ return truncateText(item.message.body) !== item.message.body.replace(/\s+/g, " ").trim();
26
+ }
8
27
  export function formatPinetReadResultFull(result, options) {
9
28
  const scope = options.threadId ? `thread ${options.threadId}` : "your Pinet inbox";
10
29
  const mode = options.unreadOnly === false ? "latest" : "unread";
@@ -15,20 +34,13 @@ export function formatPinetReadResultFull(result, options) {
15
34
  if (result.messages.length > 0) {
16
35
  lines.push("");
17
36
  for (const item of result.messages) {
18
- const classification = classifyPinetMail({
19
- source: item.message.source,
20
- threadId: item.message.threadId,
21
- sender: item.message.sender,
22
- body: item.message.body,
23
- metadata: item.message.metadata,
24
- });
25
- const label = formatPinetMailClassLabel(classification.class);
37
+ const label = formatPinetMailClassLabel(classifyReadMessage(item));
26
38
  lines.push(`- [${label}] [${item.message.source}/${item.message.threadId} #${item.message.id}] ${item.message.sender}: ${item.message.body}`);
27
39
  }
28
40
  }
29
41
  if (result.unreadThreads.length > 0) {
30
42
  lines.push("", "Unread thread pointers:");
31
- for (const thread of result.unreadThreads.slice(0, 10)) {
43
+ for (const thread of result.unreadThreads.slice(0, COMPACT_READ_DETAIL_LIMIT)) {
32
44
  const label = formatPinetMailClassLabel(thread.highestMailClass);
33
45
  const counts = summarizeUnreadThreadCounts(thread);
34
46
  lines.push(`- [${label}] ${thread.threadId} (${thread.source}${thread.channel ? `/${thread.channel}` : ""}): ${thread.unreadCount} unread${counts ? ` (${counts})` : ""}; latest #${thread.latestMessageId}; pointer=pinet action=read args.thread_id=${thread.threadId} args.unread_only=true`);
@@ -51,38 +63,54 @@ export function summarizeUnreadThreadCounts(thread) {
51
63
  .join(", ");
52
64
  }
53
65
  export function buildCompactPinetReadDetails(result) {
54
- return {
66
+ const messages = result.messages.slice(0, COMPACT_READ_DETAIL_LIMIT);
67
+ const unreadThreads = result.unreadThreads.slice(0, COMPACT_READ_DETAIL_LIMIT);
68
+ const messageTruncated = Math.max(0, result.messages.length - messages.length);
69
+ const unreadThreadTruncated = Math.max(0, result.unreadThreads.length - unreadThreads.length);
70
+ const summaryParts = [
71
+ `${result.messages.length} msg`,
72
+ `unread ${result.unreadCountBefore}→${result.unreadCountAfter}`,
73
+ result.markedReadIds.length > 0 ? `marked ${result.markedReadIds.length}` : null,
74
+ result.unreadThreads.length > 0
75
+ ? `${result.unreadThreads.length} unread thread${result.unreadThreads.length === 1 ? "" : "s"}`
76
+ : null,
77
+ ].filter((item) => Boolean(item));
78
+ const details = {
79
+ summary: summaryParts.join("; "),
55
80
  messageCount: result.messages.length,
56
- unreadCountBefore: result.unreadCountBefore,
57
- unreadCountAfter: result.unreadCountAfter,
58
- markedReadIds: result.markedReadIds,
59
- messages: result.messages.map((item) => {
60
- const classification = classifyPinetMail({
61
- source: item.message.source,
62
- threadId: item.message.threadId,
63
- sender: item.message.sender,
64
- body: item.message.body,
65
- metadata: item.message.metadata,
66
- });
67
- return {
68
- inboxId: item.inboxId,
69
- messageId: item.message.id,
70
- threadId: item.message.threadId,
71
- source: item.message.source,
72
- sender: item.message.sender,
73
- class: classification.class,
74
- preview: truncateText(item.message.body),
75
- };
76
- }),
77
- unreadThreads: result.unreadThreads.slice(0, 10).map((thread) => ({
81
+ unreadBefore: result.unreadCountBefore,
82
+ unreadAfter: result.unreadCountAfter,
83
+ };
84
+ if (result.markedReadIds.length > 0) {
85
+ details.markedReadCount = result.markedReadIds.length;
86
+ }
87
+ if (messages.length > 0) {
88
+ details.messages = messages.map((item) => ({
89
+ id: item.message.id,
90
+ threadId: item.message.threadId,
91
+ source: item.message.source,
92
+ sender: item.message.sender,
93
+ class: classifyReadMessage(item),
94
+ }));
95
+ details.exactBodies = "args.full=true args.unread_only=false";
96
+ }
97
+ if (messageTruncated > 0) {
98
+ details.messagesTruncated = messageTruncated;
99
+ }
100
+ if (unreadThreads.length > 0) {
101
+ details.unreadThreads = unreadThreads.map((thread) => ({
78
102
  threadId: thread.threadId,
79
103
  source: thread.source,
80
- unreadCount: thread.unreadCount,
104
+ unread: thread.unreadCount,
81
105
  latestMessageId: thread.latestMessageId,
82
- highestMailClass: thread.highestMailClass,
83
- mailClassSummary: summarizeUnreadThreadCounts(thread),
84
- })),
85
- };
106
+ class: thread.highestMailClass,
107
+ summary: summarizeUnreadThreadCounts(thread),
108
+ }));
109
+ }
110
+ if (unreadThreadTruncated > 0) {
111
+ details.unreadThreadsTruncated = unreadThreadTruncated;
112
+ }
113
+ return details;
86
114
  }
87
115
  export function formatPinetReadResultCompact(result, options) {
88
116
  const mode = options.unreadOnly === false ? "latest" : "unread";
@@ -90,5 +118,26 @@ export function formatPinetReadResultCompact(result, options) {
90
118
  const unreadThreadSuffix = result.unreadThreads.length > 0
91
119
  ? `; ${result.unreadThreads.length} unread thread${result.unreadThreads.length === 1 ? "" : "s"}`
92
120
  : "";
93
- return `Pinet read: ${result.messages.length} ${mode} message${result.messages.length === 1 ? "" : "s"}; unread ${result.unreadCountBefore}→${result.unreadCountAfter}${markedSuffix}${unreadThreadSuffix}.`;
121
+ const lines = [
122
+ `Pinet read: ${result.messages.length} ${mode} message${result.messages.length === 1 ? "" : "s"}; unread ${result.unreadCountBefore}→${result.unreadCountAfter}${markedSuffix}${unreadThreadSuffix}.`,
123
+ ];
124
+ // Show capped per-message previews for both thread-scoped and inbox-wide
125
+ // compact reads. Restricting previews to thread-scoped reads (the previous
126
+ // behavior) left inbox-wide `pinet action=read` callers with only the counts
127
+ // header, which pushed agents toward `full=true` just to see what arrived.
128
+ // The 3-message + 96-char cap already keeps the output bounded.
129
+ if (result.messages.length > 0) {
130
+ const shownMessages = result.messages.slice(0, COMPACT_READ_TEXT_MESSAGE_LIMIT);
131
+ lines.push(...shownMessages.map(formatCompactMessagePreview));
132
+ const truncated = result.messages.length - shownMessages.length;
133
+ if (truncated > 0) {
134
+ lines.push(`… ${truncated} more message${truncated === 1 ? "" : "s"}.`);
135
+ }
136
+ if (truncated > 0 || shownMessages.some(isMessageBodyTruncated)) {
137
+ // Stated as a diagnostic affordance rather than a directive so we don't
138
+ // actively push routine reads toward `full=true`.
139
+ lines.push("args.full=true args.unread_only=false returns verbatim bodies.");
140
+ }
141
+ }
142
+ return lines.join("\n");
94
143
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pinet/pinet-core",
3
- "version": "0.1.2",
3
+ "version": "0.2.1",
4
4
  "type": "module",
5
5
  "description": "Pinet runtime core for pi — broker/follower orchestration and mesh tooling",
6
6
  "author": "Will Porcellini <5994936+gugu91@users.noreply.github.com>",
@@ -35,8 +35,8 @@
35
35
  "test": "vitest run *.test.ts"
36
36
  },
37
37
  "dependencies": {
38
- "@pinet/broker-core": "0.1.2",
39
- "@pinet/transport-core": "0.1.2"
38
+ "@pinet/broker-core": "0.2.1",
39
+ "@pinet/transport-core": "0.2.1"
40
40
  },
41
41
  "types": "./dist/index.d.ts"
42
42
  }