@shumkov/orchestra 0.4.0 → 0.4.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.
@@ -1470,6 +1470,11 @@ class CliProcess extends Process {
1470
1470
  files: args.files,
1471
1471
  messageId: args.message_id, // 0.13: edit_message target bubble
1472
1472
  sourceMsgId, // reaction/quote target (A2)
1473
+ // Quote participant rides the SAME ledger entry as sourceMsgId, so the quote's
1474
+ // author can never disagree with its target. Present only when there's a resolved
1475
+ // quote target; null otherwise so the dispatcher omits the quote (never a
1476
+ // half-built quote — WhatsApp needs both fields).
1477
+ participantJid: sourceMsgId != null ? (sourceEntry?.participantJid ?? null) : null,
1473
1478
  sessionCwd: this.sessionCwd, // P0 #2: dispatcher uses this to allowlist file roots
1474
1479
  maxOutboundFileBytes: this.maxOutboundFileBytes, // backend/chat-derived upload cap
1475
1480
  });
@@ -1678,11 +1683,15 @@ class CliProcess extends Process {
1678
1683
 
1679
1684
  // ─── 0.13 D2: InputLedger ──────────────────────────────────────────
1680
1685
 
1681
- _ledgerAdd(turnId, { source, msgId = null } = {}) {
1686
+ _ledgerAdd(turnId, { source, msgId = null, participantJid = null } = {}) {
1682
1687
  this.inputLedger.set(turnId, {
1683
1688
  turnId,
1684
1689
  source,
1685
1690
  msgId: msgId != null ? String(msgId) : null,
1691
+ // The source message's author JID, carried so a reply can quote it (WhatsApp
1692
+ // threading needs both the stanza id AND the participant). Null for backends /
1693
+ // callers that don't supply one — the quote is then simply omitted downstream.
1694
+ participantJid: participantJid != null ? String(participantJid) : null,
1686
1695
  chatId: this.chatId,
1687
1696
  writtenAt: Date.now(),
1688
1697
  state: 'written',
@@ -2546,7 +2555,11 @@ class CliProcess extends Process {
2546
2555
  // 0.13 D2: ledger the primary + keep the exact envelope for the delivery
2547
2556
  // watchdog's idempotent re-write (the pending owns it — no text in the
2548
2557
  // ledger, events stay content-free per L13).
2549
- this._ledgerAdd(turnId, { source: 'primary', msgId: opts.context?.sourceMsgId });
2558
+ this._ledgerAdd(turnId, {
2559
+ source: 'primary',
2560
+ msgId: opts.context?.sourceMsgId,
2561
+ participantJid: opts.context?.participantJid,
2562
+ });
2550
2563
 
2551
2564
  // Review F#18: bridge-disconnect TOCTOU. The bridgeReady check at
2552
2565
  // top of send() can race the bridge socket close. If the bridge
@@ -105,6 +105,15 @@ function _maybeWarnR12Migration({ rawPm, canonical, chatId, threadId, chatCfg, t
105
105
  * @param {string} [opts.channelsClaudeBin] — absolute path to pinned claude binary;
106
106
  * required when ANY chat routes to 'cli'. (Name kept for back-compat with
107
107
  * existing wiring; can be renamed to `claudeBin` in a future refactor.)
108
+ * @param {string|Function} [opts.displayHint] — surface-rendering hint prepended to
109
+ * the CliProcess system prompt. Accepts EITHER a static string (applied to every
110
+ * session) OR a resolver `(chatId, threadId, config) => string` invoked once per
111
+ * spawn, just before the CliProcess is constructed. The resolver receives the
112
+ * spawning chat/topic and the factory's config so the consumer can implement its
113
+ * own per-chat/topic precedence (e.g. a per-chat rich-text toggle) without the
114
+ * engine knowing anything about the consumer's config shape. The resolved string
115
+ * is what reaches CliProcess. Only the 'cli' backend uses this; the 'sdk' backend
116
+ * gets its per-chat hint via spawnFn instead.
108
117
  * @returns {Function} processFactory(sessionKey, ctx) → Process
109
118
  */
110
119
  function createProcessFactory({
@@ -153,13 +162,20 @@ function createProcessFactory({
153
162
  `falling back to SdkProcess. Pass these to createProcessFactory.`,
154
163
  );
155
164
  } else {
165
+ // displayHint may be a static string (same hint for every session) or a
166
+ // resolver called per spawn with the current chat/topic and config, so the
167
+ // consumer can vary the hint per chat (e.g. a per-chat rich-text toggle).
168
+ // The string form is passed through unchanged.
169
+ const resolvedDisplayHint = typeof displayHint === 'function'
170
+ ? displayHint(chatId, threadId, config)
171
+ : displayHint;
156
172
  return new CliProcess({
157
173
  sessionKey, chatId, threadId, label,
158
174
  tmuxRunner,
159
175
  botName,
160
176
  claudeBin: channelsClaudeBin,
161
177
  toolDispatcher,
162
- displayHint,
178
+ displayHint: resolvedDisplayHint,
163
179
  maxOutboundFileBytes,
164
180
  sessionPrefix, bridgeServerName, appDataDir, attachmentBase, productName, surfaceName,
165
181
  logger,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shumkov/orchestra",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "Drive interactive Claude Code CLI sessions: spawn, inject messages via the MCP channels bridge, observe turns, recover. The transport-agnostic session engine extracted from polygram, shared by polygram (Telegram) and water (WhatsApp).",
5
5
  "type": "commonjs",
6
6
  "main": "index.js",