@yankeguo/dsh-devlead-protocol 0.1.0 → 0.1.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.
package/lib/client.js CHANGED
@@ -23,8 +23,9 @@ var DEVLEAD_TRANSITIONS = [
23
23
  "interrupted",
24
24
  "forked"
25
25
  ];
26
+ var TRANSITION_SET = new Set(DEVLEAD_TRANSITIONS);
26
27
  function isDevLeadTransition(value) {
27
- return typeof value === "string" && DEVLEAD_TRANSITIONS.includes(value);
28
+ return typeof value === "string" && TRANSITION_SET.has(value);
28
29
  }
29
30
  function notificationId(sessionId, turn, transition) {
30
31
  return `${sessionId}:${turn}:${transition}`;
@@ -32,8 +33,11 @@ function notificationId(sessionId, turn, transition) {
32
33
  function excerptLine(text, max) {
33
34
  const collapsed = text.replace(/\s+/gu, " ").trim();
34
35
  if (collapsed.length === 0) return void 0;
35
- if (collapsed.length <= max) return collapsed;
36
- return `${collapsed.slice(0, Math.max(0, max - 1))}\u2026`;
36
+ const budget = Number.isFinite(max) ? Math.floor(max) : Number.POSITIVE_INFINITY;
37
+ if (budget < 1) return void 0;
38
+ const points = Array.from(collapsed);
39
+ if (points.length <= budget) return collapsed;
40
+ return `${points.slice(0, budget - 1).join("")}\u2026`;
37
41
  }
38
42
  var TRANSITION_LABELS = {
39
43
  completed: "completed",
@@ -47,11 +51,18 @@ var TRANSITION_LABELS = {
47
51
  function transitionLabel(transition) {
48
52
  return TRANSITION_LABELS[transition];
49
53
  }
54
+ function presentLine(value) {
55
+ if (value === void 0) return void 0;
56
+ const trimmed = value.trim();
57
+ return trimmed.length === 0 ? void 0 : trimmed;
58
+ }
50
59
  function notificationLine(notification) {
51
- const who = notification.sessionTitle === void 0 ? notification.sessionId : `${notification.sessionTitle} (${notification.sessionId})`;
52
- const error = notification.error === void 0 ? "" : `: ${notification.error}`;
53
- const summary = notification.error === void 0 && notification.summary !== void 0 ? `: ${notification.summary}` : "";
54
- return `${who} \u2014 turn ${notification.turn} ${transitionLabel(notification.transition)}${error}${summary}`;
60
+ const title = presentLine(notification.sessionTitle);
61
+ const who = title === void 0 ? notification.sessionId : `${title} (${notification.sessionId})`;
62
+ const error = presentLine(notification.error);
63
+ const detail = error ?? presentLine(notification.summary);
64
+ const suffix = detail === void 0 ? "" : `: ${detail}`;
65
+ return `${who} \u2014 turn ${notification.turn} ${transitionLabel(notification.transition)}${suffix}`;
55
66
  }
56
67
  function notificationDigest(notifications) {
57
68
  return notifications.map(notificationLine);
package/lib/index.js CHANGED
@@ -23,8 +23,9 @@ var DEVLEAD_TRANSITIONS = [
23
23
  "interrupted",
24
24
  "forked"
25
25
  ];
26
+ var TRANSITION_SET = new Set(DEVLEAD_TRANSITIONS);
26
27
  function isDevLeadTransition(value) {
27
- return typeof value === "string" && DEVLEAD_TRANSITIONS.includes(value);
28
+ return typeof value === "string" && TRANSITION_SET.has(value);
28
29
  }
29
30
  function notificationId(sessionId, turn, transition) {
30
31
  return `${sessionId}:${turn}:${transition}`;
@@ -32,8 +33,11 @@ function notificationId(sessionId, turn, transition) {
32
33
  function excerptLine(text, max) {
33
34
  const collapsed = text.replace(/\s+/gu, " ").trim();
34
35
  if (collapsed.length === 0) return void 0;
35
- if (collapsed.length <= max) return collapsed;
36
- return `${collapsed.slice(0, Math.max(0, max - 1))}\u2026`;
36
+ const budget = Number.isFinite(max) ? Math.floor(max) : Number.POSITIVE_INFINITY;
37
+ if (budget < 1) return void 0;
38
+ const points = Array.from(collapsed);
39
+ if (points.length <= budget) return collapsed;
40
+ return `${points.slice(0, budget - 1).join("")}\u2026`;
37
41
  }
38
42
  var TRANSITION_LABELS = {
39
43
  completed: "completed",
@@ -47,11 +51,18 @@ var TRANSITION_LABELS = {
47
51
  function transitionLabel(transition) {
48
52
  return TRANSITION_LABELS[transition];
49
53
  }
54
+ function presentLine(value) {
55
+ if (value === void 0) return void 0;
56
+ const trimmed = value.trim();
57
+ return trimmed.length === 0 ? void 0 : trimmed;
58
+ }
50
59
  function notificationLine(notification) {
51
- const who = notification.sessionTitle === void 0 ? notification.sessionId : `${notification.sessionTitle} (${notification.sessionId})`;
52
- const error = notification.error === void 0 ? "" : `: ${notification.error}`;
53
- const summary = notification.error === void 0 && notification.summary !== void 0 ? `: ${notification.summary}` : "";
54
- return `${who} \u2014 turn ${notification.turn} ${transitionLabel(notification.transition)}${error}${summary}`;
60
+ const title = presentLine(notification.sessionTitle);
61
+ const who = title === void 0 ? notification.sessionId : `${title} (${notification.sessionId})`;
62
+ const error = presentLine(notification.error);
63
+ const detail = error ?? presentLine(notification.summary);
64
+ const suffix = detail === void 0 ? "" : `: ${detail}`;
65
+ return `${who} \u2014 turn ${notification.turn} ${transitionLabel(notification.transition)}${suffix}`;
55
66
  }
56
67
  function notificationDigest(notifications) {
57
68
  return notifications.map(notificationLine);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yankeguo/dsh-devlead-protocol",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Pure shared protocol of the devlead plugin suite: durable mode, watched-session and notification types, plus the pure fold and formatting rules used by both Host and browser.",
5
5
  "license": "MIT",
6
6
  "type": "module",