@phren/cli 0.3.73 → 0.3.74

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.
@@ -711,6 +711,36 @@ export function skillBody(raw) {
711
711
  const QUEUED_IMAGE_LABEL = /\[Image #\d+\]/;
712
712
  const QUEUED_IMAGE_LABELS = /\[Image #\d+\]/g;
713
713
  const ATTACHED_FILES_FOOTER = /Attached files on this computer:\s*$/;
714
+ /** How much of one agent's message crosses: the terminal folds it too. */
715
+ const PEER_MESSAGE_LIMIT = 32_768;
716
+ const HANDBACK_FRAME = /^\[Subagent hand-back\][\s\S]*?The report follows:\n/;
717
+ /** A message another agent sent this session (a teammate, a subagent's
718
+ * hand-back or another Claude session), which Claude Code delivers as a hidden
719
+ * user row when the agent is idle, or a queued_command attachment mid-turn,
720
+ * both naming it with `origin.kind: "peer"`. The terminal shows it as
721
+ * "Message from @name"; only the sender's name and the words cross, never the
722
+ * envelope, socket path or ids. */
723
+ export function peerMessage(raw, includeSidechain = false) {
724
+ if (raw.isSidechain && !includeSidechain)
725
+ return undefined;
726
+ const attachment = object(raw.attachment);
727
+ const origin = raw.type === "user" ? object(raw.origin)
728
+ : raw.type === "attachment" && attachment.type === "queued_command" ? object(attachment.origin) : {};
729
+ if (origin.kind !== "peer" || typeof origin.body !== "string")
730
+ return undefined;
731
+ const handback = origin.handback === true;
732
+ // A hand-back's body opens with the harness's framing and indents the
733
+ // report two spaces; the report itself is carried alongside when it fits.
734
+ const text = handback && typeof origin.handbackReportText === "string" ? origin.handbackReportText
735
+ : handback && HANDBACK_FRAME.test(origin.body) ? origin.body.replace(HANDBACK_FRAME, "").replace(/^ {2}/gm, "")
736
+ : origin.body;
737
+ if (!text.trim())
738
+ return undefined;
739
+ const name = typeof origin.name === "string" ? origin.name.replace(/[\p{Cc}\p{Cf}]+/gu, " ").trim().slice(0, 80) : "";
740
+ return { type: "phren_peer_message", timestamp: raw.timestamp, ...(typeof raw.uuid === "string" ? { uuid: raw.uuid } : {}),
741
+ name: name || "agent", ...(handback ? { handback: true } : {}),
742
+ text: text.length > PEER_MESSAGE_LIMIT ? text.slice(0, PEER_MESSAGE_LIMIT) + "\n…" : text };
743
+ }
714
744
  /** A phren UserPromptSubmit injection, as `{ type: "phren_hook_context",
715
745
  * parentUuid, content }`, or undefined for any other row. */
716
746
  export function phrenHookContext(raw, includeSidechain = false) {
@@ -721,6 +751,9 @@ export function phrenHookContext(raw, includeSidechain = false) {
721
751
  // its hook output. Only whether it was a background notification crosses,
722
752
  // so the phone can leave a notification's injection out.
723
753
  if (attachment.type === "queued_command") {
754
+ const peer = peerMessage(raw, includeSidechain);
755
+ if (peer)
756
+ return peer;
724
757
  return { type: "phren_turn_input", timestamp: raw.timestamp, notification: attachment.commandMode === "task-notification" };
725
758
  }
726
759
  if (attachment.type !== "hook_success" || attachment.hookEvent !== "UserPromptSubmit")
@@ -877,6 +910,8 @@ export function visibleClaudeEvent(raw, includeSidechain = false, queue) {
877
910
  // origin says "task-notification" (sometimes wrapped in a system reminder).
878
911
  // It is a notice, not a prompt: normalize only its public envelope and never
879
912
  // let established notification provenance fall through as ordinary user text.
913
+ if (raw.type === "user" && object(raw.origin).kind === "peer")
914
+ return peerMessage(raw, includeSidechain);
880
915
  if (raw.type === "user") {
881
916
  const content = object(raw.message).content;
882
917
  const text = typeof content === "string" ? content