pantheon-cli 0.3.1 → 0.3.2

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.
Files changed (2) hide show
  1. package/dist/pantheon.mjs +73 -8
  2. package/package.json +1 -1
package/dist/pantheon.mjs CHANGED
@@ -46129,6 +46129,47 @@ function ensureChannelSpace(home, name) {
46129
46129
  touch(home, meta);
46130
46130
  return { channel: meta.slug, space: slug, created };
46131
46131
  }
46132
+ var MAX_EMOJI = 16;
46133
+ function editMessage(home, name, id, edit) {
46134
+ const meta = requireChannel(home, name);
46135
+ const path = join6(channelDir(home, meta.slug), "messages.jsonl");
46136
+ const parsed = (existsSync6(path) ? readFileSync6(path, "utf8").split("\n") : []).filter((line) => line.trim()).map((line) => {
46137
+ try {
46138
+ return JSON.parse(line);
46139
+ } catch {
46140
+ return line;
46141
+ }
46142
+ });
46143
+ const all = parsed.filter((item) => typeof item !== "string");
46144
+ const target = all.find((message) => message.id === id);
46145
+ if (!target) throw new Error(`No message ${oneLine(id, 64)} in #${meta.slug}.`);
46146
+ const next = edit(target, all);
46147
+ const lines = parsed.flatMap((item) => {
46148
+ if (typeof item === "string") return [item];
46149
+ if (item.id !== id) return [JSON.stringify(item)];
46150
+ return next ? [JSON.stringify(next)] : [];
46151
+ });
46152
+ writeFileSync5(path, lines.length ? `${lines.join("\n")}
46153
+ ` : "");
46154
+ touch(home, meta);
46155
+ return { channel: meta.slug, message: next ? { ...next, text: sanitizeText(next.text) } : null };
46156
+ }
46157
+ function reactToChannelMessage(home, name, id, input) {
46158
+ const emoji2 = (input.emoji || "").trim();
46159
+ if (!emoji2 || emoji2.length > MAX_EMOJI || /[\s<>]/.test(emoji2)) throw new Error("React with one emoji, like \u{1F44D}.");
46160
+ const who = !input.by || input.by === "you" ? "you" : resolveAgentRef(home, input.by).space;
46161
+ return editMessage(home, name, id, (message) => {
46162
+ const reactions = { ...message.reactions ?? {} };
46163
+ const people = new Set(reactions[emoji2] ?? []);
46164
+ if (input.remove) people.delete(who);
46165
+ else people.add(who);
46166
+ if (people.size) reactions[emoji2] = [...people];
46167
+ else delete reactions[emoji2];
46168
+ const next = { ...message, reactions };
46169
+ if (!Object.keys(reactions).length) delete next.reactions;
46170
+ return next;
46171
+ });
46172
+ }
46132
46173
  function noteChannelHandoff(home, name, input) {
46133
46174
  const meta = requireChannel(home, name);
46134
46175
  const message = appendMessage(home, meta.slug, {
@@ -46141,11 +46182,15 @@ function noteChannelHandoff(home, name, input) {
46141
46182
  touch(home, meta);
46142
46183
  return message;
46143
46184
  }
46185
+ function isDecision(text2) {
46186
+ return /^\s*(?:\*\*)?(?:decision|decided)(?:\*\*)?\s*[:\-–—]/i.test(text2) || /^\s*we(?:'ve| have)? decided\b/i.test(text2);
46187
+ }
46144
46188
  function postChannelMessage(home, name, input) {
46145
46189
  const meta = requireChannel(home, name);
46146
46190
  const text2 = (input.text || "").trim();
46147
46191
  if (!text2) throw new Error("Nothing to post. Pass the message text.");
46148
46192
  const thread = threadFor(home, meta.slug, input);
46193
+ const remember = Boolean(input.remember) || isDecision(text2);
46149
46194
  let agent;
46150
46195
  if (input.by === "agent") {
46151
46196
  if (!input.agent) throw new Error("Posting as an agent needs that agent's @name.");
@@ -46164,9 +46209,9 @@ function postChannelMessage(home, name, input) {
46164
46209
  ...evidence.length ? { evidence } : {},
46165
46210
  ...input.replyTo ? { replyTo: oneLine(input.replyTo, 64) } : {},
46166
46211
  ...thread ? { thread } : {},
46167
- ...input.remember ? { remembered: true } : {}
46212
+ ...remember ? { remembered: true } : {}
46168
46213
  });
46169
- if (input.remember) {
46214
+ if (remember) {
46170
46215
  appendFileSync2(join6(channelDir(home, meta.slug), "memory.md"), `- ${oneLine(text2, 1e3)}
46171
46216
  `);
46172
46217
  }
@@ -46198,6 +46243,12 @@ function mentionedAgents(home, text2) {
46198
46243
  function channelOpenQuestions(home, slug, messages = readMessages(home, slug)) {
46199
46244
  const answered = /* @__PURE__ */ new Map();
46200
46245
  for (const message of messages) {
46246
+ for (const who of Object.values(message.reactions ?? {}).flat()) {
46247
+ if (who === "you") continue;
46248
+ const set2 = answered.get(message.id) ?? /* @__PURE__ */ new Set();
46249
+ set2.add(who);
46250
+ answered.set(message.id, set2);
46251
+ }
46201
46252
  if (message.kind !== "answer" || !message.replyTo || !message.agent) continue;
46202
46253
  const set = answered.get(message.replyTo) ?? /* @__PURE__ */ new Set();
46203
46254
  set.add(message.agent);
@@ -46231,7 +46282,7 @@ function channelOpenQuestions(home, slug, messages = readMessages(home, slug)) {
46231
46282
  if (!list.includes(message.agent)) list.push(message.agent);
46232
46283
  return [];
46233
46284
  }
46234
- if (message.kind !== "post" || message.by !== "human") return [];
46285
+ if (message.kind !== "post" || message.by !== "human" || message.deleted) return [];
46235
46286
  const mentioned2 = mentionedAgents(home, message.text);
46236
46287
  const asked = mentioned2.length ? mentioned2 : direct ? direct : thread ? (talking.get(thread) ?? []).filter((agent) => !isNoteTaker(agent)) : [];
46237
46288
  const waiting = asked.filter((agent) => !answered.get(message.id)?.has(agent));
@@ -48273,7 +48324,7 @@ function captureNeedsTranscript(error2) {
48273
48324
  const message = error2 instanceof Error ? error2.message : String(error2);
48274
48325
  return message.includes("No local conversation history was found") || message.includes("does not expose this conversation record");
48275
48326
  }
48276
- function handoffQualityReceipt(written, sync2) {
48327
+ function handoffQualityReceipt(written, sync2, agent) {
48277
48328
  const providerSkipped = sync2.skipped ?? [];
48278
48329
  const suppliedCoverageUnknown = !written.capturedFrom;
48279
48330
  const incomplete = written.truncated || written.skippedTotal > 0 || providerSkipped.length > 0 || sync2.ok === false;
@@ -48328,6 +48379,7 @@ function handoffQualityReceipt(written, sync2) {
48328
48379
  explanation: incomplete ? "A percentage is not shown because Pantheon cannot honestly quantify unknown or omitted context." : suppliedCoverageUnknown ? "The destination confirmed persistence, but the calling agent supplied the visible turns, so Pantheon cannot independently measure transcript coverage." : "All discovered conversation data and artifacts were captured and the destination confirmed persistence."
48329
48380
  },
48330
48381
  destination,
48382
+ handedOffTo: agent ? `${agent.name} (${agent.handle})${agent.channel ? `, the history of ${agent.channel}` : ""}` : null,
48331
48383
  conversationSafe: written.turns > 0,
48332
48384
  readyForResume: written.turns > 0 && sync2.ok !== false,
48333
48385
  capturedFrom: written.capturedFrom,
@@ -48335,6 +48387,14 @@ function handoffQualityReceipt(written, sync2) {
48335
48387
  actions: incomplete ? ["retry", "view_issue"] : []
48336
48388
  };
48337
48389
  }
48390
+ function receivingAgent(home, slug, channel) {
48391
+ try {
48392
+ const name = listSpaces(home).find((space) => space.slug === slug)?.agent?.name || slug;
48393
+ return { name, handle: `@${slug}`, ...channel ? { channel: `#${channel}` } : {} };
48394
+ } catch {
48395
+ return void 0;
48396
+ }
48397
+ }
48338
48398
  function fail(error2) {
48339
48399
  const message = error2 instanceof Error ? error2.message : String(error2);
48340
48400
  return {
@@ -48738,7 +48798,7 @@ ${GUIDE}` }]
48738
48798
  registerTool(
48739
48799
  server,
48740
48800
  "pantheon_handoff",
48741
- "Archive this chat into a Pantheon space. Trigger: /pantheon-handoff <space>; a new name creates the space. /pantheon-handoff #channel adds the chat to that channel's own history instead, so resuming the channel anywhere includes it. First call: omit transcript, transcriptFile, and transcriptFallback so Pantheon can try verified automatic capture for this client. If the result is transcript_required, tell the human in one line that you are including the conversation visible to you, then retry with the same space and attachments, transcriptFallback:true, and every visible user and assistant message copied verbatim in order (truncated:true if earlier turns are gone). If it is capture_first_required, retry once without transcript fields. Use append:true when re-sending the same chat. Attach every existing generated or uploaded file \u2014 { name, path } locally, { name, url } remotely, base64 only as a fallback \u2014 and never create a file just for the handoff. When turns were added, process the skill review and say which drafts you saved. Then report the handoffQuality receipt: lead with HANDOFF RESULTS; show complete or incomplete, turns and Tool calls captured, artifacts, decisions and unresolved issues, integrity, destination, and readiness for resume. If incomplete, list every issue and whether the conversation itself is safe; never invent an integrity percentage.",
48801
+ "Archive this chat into a Pantheon space. Trigger: /pantheon-handoff <space>; a new name creates the space. /pantheon-handoff #channel adds the chat to that channel's own history instead, so resuming the channel anywhere includes it. First call: omit transcript, transcriptFile, and transcriptFallback so Pantheon can try verified automatic capture for this client. If the result is transcript_required, tell the human in one line that you are including the conversation visible to you, then retry with the same space and attachments, transcriptFallback:true, and every visible user and assistant message copied verbatim in order (truncated:true if earlier turns are gone). If it is capture_first_required, retry once without transcript fields. Use append:true when re-sending the same chat. Attach every existing generated or uploaded file \u2014 { name, path } locally, { name, url } remotely, base64 only as a fallback \u2014 and never create a file just for the handoff. When turns were added, process the skill review and say which drafts you saved. Then report the handoffQuality receipt: lead with HANDOFF RESULTS; show complete or incomplete, the agent it was handed off to (handedOffTo), turns and Tool calls captured, artifacts, decisions and unresolved issues, integrity, destination, and readiness for resume. If incomplete, list every issue and whether the conversation itself is safe; never invent an integrity percentage.",
48742
48802
  {
48743
48803
  space: external_exports.string(),
48744
48804
  source: external_exports.string().optional(),
@@ -48877,7 +48937,7 @@ ${GUIDE}` }]
48877
48937
  ...channelTarget ? { channel: channelTarget, note: `Added to #${channelTarget}'s own history. Resume #${channelTarget} anywhere to continue with it.` } : {},
48878
48938
  sync: sync2,
48879
48939
  storageSkipped: sync2.skipped ?? [],
48880
- handoffQuality: handoffQualityReceipt(written, sync2),
48940
+ handoffQuality: handoffQualityReceipt(written, sync2, receivingAgent(home, written.slug, channelTarget)),
48881
48941
  skillReview: review,
48882
48942
  skillReviewAction: !shouldReview ? null : {
48883
48943
  requiresAgentJudgment: true,
@@ -49212,9 +49272,9 @@ ${GUIDE}` }]
49212
49272
  registerTool(
49213
49273
  server,
49214
49274
  "pantheon_channel",
49215
- "Channels group handoff agents. action list: every channel. read: a channel's members, memory and latest messages. create: a new #name, optionally with agents and a topic. add: merge agents into a channel, so questions there search all of them; nothing is copied, and remove undoes it. remove: take one agent out. post: add a message, only when the human asks to post or record something; remember:true also saves it to the channel memory every resume loads; as_agent with evidence and reply_to posts an agent's answer to an open question (it lands in the question's thread when there is one); thread posts as a reply under that message. read and resume list openQuestions: posts that @mention an agent, or reply in a thread an agent is part of, that it has not answered yet. Messages carry thread when they are thread replies. A channel of kind dm (named dm-<agent>) is the human's direct line to one agent: every post there asks that agent. Messages are visible in the Pantheon app.",
49275
+ "Channels group handoff agents. action list: every channel. read: a channel's members, memory and latest messages. create: a new #name, optionally with agents and a topic. add: merge agents into a channel, so questions there search all of them; nothing is copied, and remove undoes it. remove: take one agent out. post: add a message, only when the human asks to post or record something; remember:true also saves it to the channel memory every resume loads; as_agent with evidence and reply_to posts an agent's answer to an open question (it lands in the question's thread when there is one); thread posts as a reply under that message. read and resume list openQuestions: posts that @mention an agent, or reply in a thread an agent is part of, that it has not answered yet. Messages carry thread when they are thread replies. A channel of kind dm (named dm-<agent>) is the human's direct line to one agent: every post there asks that agent. react: put one emoji (text) on the message reply_to, as_agent for the agent; when a post only needs an acknowledgement (thanks, ok, done), react instead of posting, which also answers it. Messages are visible in the Pantheon app.",
49216
49276
  {
49217
- action: external_exports.enum(["list", "read", "create", "add", "remove", "post"]),
49277
+ action: external_exports.enum(["list", "read", "create", "add", "remove", "post", "react"]),
49218
49278
  channel: external_exports.string().trim().max(65).optional().describe("#name. Required for every action except list."),
49219
49279
  agents: external_exports.array(external_exports.string().trim().min(1).max(130)).max(20).optional().describe("@agents to create the channel with, add, or (one) remove."),
49220
49280
  topic: external_exports.string().max(300).optional().describe("One line on what the channel is for (create only)."),
@@ -49248,6 +49308,11 @@ ${GUIDE}` }]
49248
49308
  if (!agents?.length) throw new Error("Name the agent to remove, like @preorders.");
49249
49309
  return removeChannelMember(home, channel, agents[0], { via });
49250
49310
  }
49311
+ if (action === "react") {
49312
+ if (!reply_to) throw new Error("Name the message to react to with reply_to.");
49313
+ if (!text2) throw new Error("Pass the emoji as text, like \u{1F44D}.");
49314
+ return reactToChannelMessage(home, channel, reply_to, { emoji: text2, ...as_agent ? { by: as_agent } : {} });
49315
+ }
49251
49316
  if (!text2) throw new Error("Nothing to post. Pass text.");
49252
49317
  return postChannelMessage(home, channel, {
49253
49318
  text: text2,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pantheon-cli",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "Carry agent conscience between AI coding agents. Hand off a conversation in one agent, resume it in another.",
5
5
  "license": "MIT",
6
6
  "type": "module",