omp-channel 0.5.0 → 0.7.0

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.
@@ -0,0 +1,362 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { buildReasoning, messageIdsIn } from "./protocol.js";
3
+ import { cleanReasoning, HIDDEN_MARK, openKeyBlockAt, SECRET_LEAD } from "./redact.js";
4
+ import { textsOf } from "./turn.js";
5
+ /** The most text one report carries, in characters. */
6
+ export const MAX_REASONING_PER_REPORT = 4_000;
7
+ /** The most reasoning kept for one message, in bytes. The start is kept, the rest is dropped. */
8
+ export const MAX_REASONING_BYTES = 64 * 1024;
9
+ /** How often the text that has gathered leaves for the service. */
10
+ export const REASONING_INTERVAL_MS = 500;
11
+ /** Reports waiting to be sent, the one in flight included. More are dropped. */
12
+ export const MAX_WAITING_REASONING = 100;
13
+ /** How long one report may take before the next one is sent. */
14
+ export const REASONING_TIMEOUT_MS = 5_000;
15
+ /** How long a reply or a failure report waits for the reasoning that comes before it. */
16
+ export const REASONING_FLUSH_TIMEOUT_MS = 1_000;
17
+ const MAX_REMEMBERED = 1000;
18
+ /** Between two blocks of thinking of one message. */
19
+ const BLOCK_SEPARATOR = "\n\n";
20
+ /**
21
+ * Tells the service what the agent thinks while it works on a message (docs/protocol.md,
22
+ * "Reasoning"). The text of a message is cut into pieces at places where no secret can be split,
23
+ * cleaned, and sent in order, one report at a time, about twice a second. The work belongs to the
24
+ * newest open message of the last prompt that carried one. Nothing is said about a prompt typed at
25
+ * the terminal. The reports never hold the agent back.
26
+ */
27
+ export class ReasoningReports {
28
+ #options;
29
+ #messages = [];
30
+ #states = new Map();
31
+ /** The block of thinking being written, by its index in the message, and the message it is for. */
32
+ #blocks = new Map();
33
+ /** Messages that have their last report: nothing more is said about them. */
34
+ #closed = new Set();
35
+ #queue = Promise.resolve();
36
+ #waiting = 0;
37
+ #refused = false;
38
+ #dropped = false;
39
+ #timer;
40
+ constructor(options) {
41
+ this.#options = options;
42
+ }
43
+ /** A message entered the session. */
44
+ heard(message) {
45
+ if (typeof message !== "object" || message === null) {
46
+ return;
47
+ }
48
+ const { role, content, synthetic } = message;
49
+ if (role !== "user" && role !== "developer") {
50
+ return;
51
+ }
52
+ const ids = textsOf(content).flatMap(messageIdsIn);
53
+ if (ids.length > 0) {
54
+ const kept = this.#messages.filter((id) => !ids.includes(id));
55
+ this.#messages = [...kept, ...ids].slice(-MAX_REMEMBERED);
56
+ }
57
+ else if (role === "user" && synthetic !== true) {
58
+ // A person typed at the terminal: what follows is not for the service.
59
+ this.#messages = [];
60
+ this.#blocks.clear();
61
+ }
62
+ }
63
+ /** One event of the stream of the model. Only the thinking ones count. */
64
+ update(event) {
65
+ if (typeof event !== "object" || event === null) {
66
+ return;
67
+ }
68
+ const thinking = event;
69
+ const index = thinking.contentIndex;
70
+ if (typeof index !== "number") {
71
+ return;
72
+ }
73
+ if (thinking.type === "thinking_start") {
74
+ this.#begin(index);
75
+ }
76
+ else if (thinking.type === "thinking_delta" && typeof thinking.delta === "string") {
77
+ this.#add(index, thinking.delta);
78
+ }
79
+ else if (thinking.type === "thinking_end") {
80
+ this.#blocks.delete(index);
81
+ }
82
+ }
83
+ /**
84
+ * The message has its reply or its failure report: what is left goes now, as the last piece.
85
+ * Resolves when the reports made so far have left, or after a short wait.
86
+ */
87
+ finish(messageId) {
88
+ for (const [index, owner] of this.#blocks) {
89
+ if (owner === messageId) {
90
+ this.#blocks.delete(index);
91
+ }
92
+ }
93
+ const state = this.#states.get(messageId);
94
+ this.#states.delete(messageId);
95
+ this.#remember(messageId);
96
+ if (state !== undefined && (state.seq > 0 || state.buffer !== "")) {
97
+ this.#drain(messageId, state, true);
98
+ }
99
+ return this.#waiting === 0
100
+ ? undefined
101
+ : within(this.#queue, REASONING_FLUSH_TIMEOUT_MS).catch(() => { });
102
+ }
103
+ /** The session goes to another conversation of its own. */
104
+ reset() {
105
+ this.#messages = [];
106
+ this.#states.clear();
107
+ this.#blocks.clear();
108
+ this.#stop();
109
+ }
110
+ #begin(index) {
111
+ const target = [...this.#messages]
112
+ .reverse()
113
+ .find((id) => this.#options.conversationOfOpen(id) !== undefined && !this.#closed.has(id));
114
+ if (target === undefined) {
115
+ this.#blocks.delete(index);
116
+ return;
117
+ }
118
+ this.#blocks.set(index, target);
119
+ const state = this.#states.get(target);
120
+ if (state?.hasText === true) {
121
+ state.separatorDue = true;
122
+ }
123
+ }
124
+ #add(index, delta) {
125
+ const replyTo = this.#blocks.get(index);
126
+ if (replyTo === undefined || delta === "") {
127
+ return;
128
+ }
129
+ const conversationId = this.#options.conversationOfOpen(replyTo);
130
+ if (conversationId === undefined || this.#closed.has(replyTo)) {
131
+ // The message is answered: a delta after that is not said.
132
+ this.#blocks.delete(index);
133
+ return;
134
+ }
135
+ let state = this.#states.get(replyTo);
136
+ if (state === undefined) {
137
+ state = {
138
+ conversationId,
139
+ buffer: "",
140
+ taken: 0,
141
+ seq: 0,
142
+ truncated: false,
143
+ hasText: false,
144
+ separatorDue: false,
145
+ skipping: false,
146
+ };
147
+ remember(this.#states, replyTo, state);
148
+ }
149
+ if (state.truncated) {
150
+ return;
151
+ }
152
+ let text = state.separatorDue ? `${BLOCK_SEPARATOR}${delta}` : delta;
153
+ state.separatorDue = false;
154
+ const room = MAX_REASONING_BYTES - state.taken;
155
+ if (Buffer.byteLength(text) > room) {
156
+ text = fitBytes(text, room);
157
+ state.truncated = true;
158
+ }
159
+ state.taken += Buffer.byteLength(text);
160
+ state.hasText = state.hasText || text !== "";
161
+ state.buffer += text;
162
+ this.#schedule();
163
+ }
164
+ #schedule() {
165
+ if (this.#timer !== undefined) {
166
+ return;
167
+ }
168
+ this.#timer = setTimeout(() => {
169
+ this.#timer = undefined;
170
+ this.#tick();
171
+ }, this.#options.intervalMs ?? REASONING_INTERVAL_MS);
172
+ this.#timer.unref?.();
173
+ }
174
+ #stop() {
175
+ clearTimeout(this.#timer);
176
+ this.#timer = undefined;
177
+ }
178
+ /** One report for each message that has text waiting. */
179
+ #tick() {
180
+ let more = false;
181
+ for (const [replyTo, state] of this.#states) {
182
+ if (this.#options.conversationOfOpen(replyTo) === undefined) {
183
+ this.#states.delete(replyTo);
184
+ continue;
185
+ }
186
+ this.#drain(replyTo, state, false);
187
+ more = more || state.buffer !== "";
188
+ }
189
+ if (more) {
190
+ this.#schedule();
191
+ }
192
+ }
193
+ /** Sends the next piece of a message, or, when it is the last, all that is left. */
194
+ #drain(replyTo, state, final) {
195
+ if (!final) {
196
+ const piece = takePiece(state);
197
+ const cleaned = piece === undefined ? "" : cleanReasoning(piece);
198
+ if (cleaned !== "") {
199
+ this.#report(replyTo, state, cleaned, false);
200
+ }
201
+ return;
202
+ }
203
+ // The whole rest is cleaned in one go, so a secret that was waiting for its end is seen whole;
204
+ // then no cut can split one, and the pieces keep to the limit of a report.
205
+ const rest = state.skipping ? state.buffer.replace(/^\S*/, "") : state.buffer;
206
+ state.buffer = "";
207
+ const pieces = splitSymbols(cleanReasoning(rest), MAX_REASONING_PER_REPORT);
208
+ pieces.forEach((piece, at) => {
209
+ this.#report(replyTo, state, piece, at === pieces.length - 1);
210
+ });
211
+ }
212
+ #report(replyTo, state, text, final) {
213
+ if (this.#waiting >= MAX_WAITING_REASONING) {
214
+ if (!this.#dropped) {
215
+ this.#options.log("reasoning reports are dropped: the service is too slow");
216
+ }
217
+ this.#dropped = true;
218
+ return;
219
+ }
220
+ const report = buildReasoning(state.conversationId, replyTo, { seq: state.seq, text, final, truncated: state.truncated }, { messageId: this.#newId(), at: this.#options.now?.() ?? new Date() });
221
+ state.seq += 1;
222
+ this.#waiting += 1;
223
+ this.#queue = this.#queue.then(() => this.#deliver(report));
224
+ }
225
+ /** One attempt. A refusal is logged once until a report is accepted again. */
226
+ async #deliver(report) {
227
+ try {
228
+ await within(this.#options.send(report), REASONING_TIMEOUT_MS);
229
+ this.#refused = false;
230
+ this.#dropped = false;
231
+ }
232
+ catch (error) {
233
+ if (!this.#refused) {
234
+ const name = error instanceof Error ? error.name : "unknown";
235
+ this.#options.log(`reasoning was not reported (${name})`);
236
+ }
237
+ this.#refused = true;
238
+ }
239
+ finally {
240
+ this.#waiting -= 1;
241
+ }
242
+ }
243
+ #remember(messageId) {
244
+ this.#closed.add(messageId);
245
+ if (this.#closed.size > MAX_REMEMBERED) {
246
+ const oldest = this.#closed.values().next();
247
+ if (oldest.value !== undefined) {
248
+ this.#closed.delete(oldest.value);
249
+ }
250
+ }
251
+ }
252
+ #newId() {
253
+ return this.#options.newId?.() ?? randomUUID();
254
+ }
255
+ }
256
+ /**
257
+ * Cuts the next piece off the text of a message: at most `MAX_REASONING_PER_REPORT` characters, and
258
+ * only where no secret can be split. A cut falls on a space or a line break, never after the name
259
+ * of a secret (`password:`), never inside a private key that is not closed. A run of that many
260
+ * characters with no break is hidden whole, and what follows of it is dropped. Undefined while
261
+ * there is nothing that can leave yet.
262
+ */
263
+ function takePiece(state) {
264
+ if (state.skipping) {
265
+ const rest = state.buffer.search(/\s/);
266
+ if (rest === -1) {
267
+ state.buffer = "";
268
+ return undefined;
269
+ }
270
+ state.buffer = state.buffer.slice(rest);
271
+ state.skipping = false;
272
+ }
273
+ const text = state.buffer;
274
+ if (text === "") {
275
+ return undefined;
276
+ }
277
+ const open = openKeyBlockAt(text);
278
+ const limit = open === -1 ? text.length : open;
279
+ const window = Math.min(limit, lastWholeSymbol(text, MAX_REASONING_PER_REPORT));
280
+ let cut = -1;
281
+ for (let at = window; at > 0; at -= 1) {
282
+ if (/\s/.test(text.charAt(at - 1)) && !SECRET_LEAD.test(text.slice(0, at))) {
283
+ cut = at;
284
+ break;
285
+ }
286
+ }
287
+ if (cut <= 0) {
288
+ // Nothing to cut at yet. A run that fills a whole report without a break is a token.
289
+ if (open === -1 &&
290
+ window >= MAX_REASONING_PER_REPORT - 1 &&
291
+ !/\s/.test(text.slice(0, window))) {
292
+ state.buffer = text.slice(window);
293
+ state.skipping = true;
294
+ return HIDDEN_MARK;
295
+ }
296
+ return undefined;
297
+ }
298
+ state.buffer = text.slice(cut);
299
+ return text.slice(0, cut);
300
+ }
301
+ /** The largest index up to `max` characters that does not split a surrogate pair. */
302
+ function lastWholeSymbol(text, max) {
303
+ if (text.length <= max) {
304
+ return text.length;
305
+ }
306
+ const code = text.charCodeAt(max - 1);
307
+ return code >= 0xd800 && code <= 0xdbff ? max - 1 : max;
308
+ }
309
+ /** The text in pieces of at most `size` characters, none of them splitting a surrogate pair. */
310
+ function splitSymbols(text, size) {
311
+ const pieces = [];
312
+ let rest = text;
313
+ while (rest.length > size) {
314
+ const at = lastWholeSymbol(rest, size);
315
+ pieces.push(rest.slice(0, at));
316
+ rest = rest.slice(at);
317
+ }
318
+ pieces.push(rest);
319
+ return pieces;
320
+ }
321
+ /** The start of the text that fits in `bytes`, without half a character. */
322
+ function fitBytes(text, bytes) {
323
+ let result = "";
324
+ let used = 0;
325
+ for (const symbol of text) {
326
+ const size = Buffer.byteLength(symbol);
327
+ if (used + size > bytes) {
328
+ break;
329
+ }
330
+ result += symbol;
331
+ used += size;
332
+ }
333
+ return result;
334
+ }
335
+ /** The promise, or a rejection after `ms`. */
336
+ async function within(promise, ms) {
337
+ let timer;
338
+ const late = new Promise((_resolve, reject) => {
339
+ timer = setTimeout(() => {
340
+ const error = new Error("no answer in time");
341
+ error.name = "TimeoutError";
342
+ reject(error);
343
+ }, ms);
344
+ });
345
+ try {
346
+ await Promise.race([promise, late]);
347
+ }
348
+ finally {
349
+ clearTimeout(timer);
350
+ }
351
+ }
352
+ /** Adds to a map that keeps only the newest entries. */
353
+ function remember(map, key, value) {
354
+ map.set(key, value);
355
+ if (map.size > MAX_REMEMBERED) {
356
+ const oldest = map.keys().next();
357
+ if (oldest.value !== undefined) {
358
+ map.delete(oldest.value);
359
+ }
360
+ }
361
+ }
362
+ //# sourceMappingURL=reasoning.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reasoning.js","sourceRoot":"","sources":["../src/reasoning.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UA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,GAAG,UAAU,CAAC,GAAG,EAAE;YACtB,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;YAC7C,KAAK,CAAC,IAAI,GAAG,cAAc,CAAC;YAC5B,MAAM,CAAC,KAAK,CAAC,CAAC;QAChB,CAAC,EAAE,EAAE,CAAC,CAAC;IACT,CAAC,CAAC,CAAC;IACH,IAAI,CAAC;QACH,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC;IACtC,CAAC;YAAS,CAAC;QACT,YAAY,CAAC,KAAK,CAAC,CAAC;IACtB,CAAC;AACH,CAAC;AAED,wDAAwD;AACxD,SAAS,QAAQ,CAAI,GAAmB,EAAE,GAAW,EAAE,KAAQ;IAC7D,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACpB,IAAI,GAAG,CAAC,IAAI,GAAG,cAAc,EAAE,CAAC;QAC9B,MAAM,MAAM,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC;QACjC,IAAI,MAAM,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;YAC/B,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC;AACH,CAAC"}
package/dist/redact.d.ts CHANGED
@@ -15,6 +15,17 @@ export declare function cleanReason(raw: string): string | undefined;
15
15
  * the reply tool. At most `maxLength` characters. Undefined when nothing is left.
16
16
  */
17
17
  export declare function cleanText(raw: string, maxLength: number): string | undefined;
18
+ /**
19
+ * The same hiding for a piece of reasoning: line breaks and spaces stay, because the pieces of a
20
+ * message are joined as they are. Not trimmed, not cut: the caller cuts at a safe place.
21
+ */
22
+ export declare function cleanReasoning(raw: string): string;
23
+ /** Where a private key block that is not closed yet begins, or -1. */
24
+ export declare function openKeyBlockAt(text: string): number;
25
+ /** The text a secret may continue after: a name that holds one, or the word before its value. */
26
+ export declare const SECRET_LEAD: RegExp;
27
+ /** The hidden mark, for the callers that replace a run themselves. */
28
+ export declare const HIDDEN_MARK = "[hidden]";
18
29
  /**
19
30
  * The line of one tool use: the tool name and the intent stated for the call, on one line of at
20
31
  * most `MAX_ACTIVITY_LENGTH` characters. The intent is free text, and some tools build it from
package/dist/redact.js CHANGED
@@ -59,6 +59,30 @@ export function cleanReason(raw) {
59
59
  export function cleanText(raw, maxLength) {
60
60
  return cut(hideSecrets(withoutControls(raw, "\n\t")).trim(), maxLength);
61
61
  }
62
+ /**
63
+ * The same hiding for a piece of reasoning: line breaks and spaces stay, because the pieces of a
64
+ * message are joined as they are. Not trimmed, not cut: the caller cuts at a safe place.
65
+ */
66
+ export function cleanReasoning(raw) {
67
+ return hideSecrets(withoutControls(raw, "\n\t"));
68
+ }
69
+ /** Where a private key block that is not closed yet begins, or -1. */
70
+ export function openKeyBlockAt(text) {
71
+ const begin = /-----BEGIN [A-Z0-9 ]*PRIVATE KEY-----/g;
72
+ let open = -1;
73
+ for (const match of text.matchAll(begin)) {
74
+ const from = (match.index ?? 0) + match[0].length;
75
+ if (!/-----END [A-Z0-9 ]*PRIVATE KEY-----/.test(text.slice(from))) {
76
+ open = match.index ?? 0;
77
+ break;
78
+ }
79
+ }
80
+ return open;
81
+ }
82
+ /** The text a secret may continue after: a name that holds one, or the word before its value. */
83
+ export const SECRET_LEAD = /(?:[:=]|\b(?:bearer|basic|token|authorization))["']?\s*$/i;
84
+ /** The hidden mark, for the callers that replace a run themselves. */
85
+ export const HIDDEN_MARK = HIDDEN;
62
86
  /**
63
87
  * The line of one tool use: the tool name and the intent stated for the call, on one line of at
64
88
  * most `MAX_ACTIVITY_LENGTH` characters. The intent is free text, and some tools build it from
@@ -1 +1 @@
1
- {"version":3,"file":"redact.js","sourceRoot":"","sources":["../src/redact.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,CAAC;AACrC,MAAM,CAAC,MAAM,mBA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AChB,CAAC"}
package/docs/protocol.md CHANGED
@@ -20,6 +20,7 @@ The machine-readable schemas are in [`schema/`](https://github.com/tommasomarchi
20
20
  | `status.schema.json` | agent state the agent reports to the service |
21
21
  | `failure.schema.json` | a turn that ended in an error and left a message unanswered |
22
22
  | `activity.schema.json` | a tool the agent uses for a message (optional report) |
23
+ | `reasoning.schema.json` | a piece of the agent's reasoning for a message (optional report) |
23
24
  | `config.schema.json` | the omp-channel configuration file |
24
25
 
25
26
  The TypeScript module `src/protocol.ts` implements the same rules. Both must change together.
@@ -158,6 +159,7 @@ Paths are relative to `service.url` and configurable in `service.paths`. Default
158
159
  | Status | `POST /status` | agent status (section 8) |
159
160
  | Failure | `POST /failures` | failed turn (section 9) |
160
161
  | Activity | no default path | activity (section 10) |
162
+ | Reasoning | no default path | reasoning (section 11) |
161
163
 
162
164
  All calls carry `Authorization: Bearer <key>`. A non-2xx answer is an error. The key is never
163
165
  included in a log line, an error message or a tool result.
@@ -240,11 +242,12 @@ that implements `ChannelAdapter` (`src/adapter.ts`):
240
242
  ```ts
241
243
  interface ChannelAdapter {
242
244
  receive(signal: AbortSignal): AsyncIterable<{ deliveryId?: string; event: InboundEvent }>;
243
- reply(reply: OutboundReply): Promise<void>; // required
245
+ reply(reply: OutboundReply): Promise<void | { questionRefused?: string }>; // required
244
246
  ack?(deliveryId: string): Promise<void>; // after admission
245
247
  status?(status: OutboundStatus): Promise<void>; // best effort
246
248
  failure?(failure: OutboundFailure): Promise<void>; // a message got no answer (section 9)
247
249
  activity?(activity: OutboundActivity): Promise<void>; // a tool in use (section 10)
250
+ reasoning?(reasoning: OutboundReasoning): Promise<void>; // a piece of reasoning (section 11)
248
251
  interrupt?(conversationId: string): Promise<void>; // after an interrupt is applied
249
252
  close?(conversationId: string): Promise<void>; // after a close is applied
250
253
  describe?(): Promise<string> | string; // plain-text state for the /channel-status command
@@ -252,7 +255,9 @@ interface ChannelAdapter {
252
255
  ```
253
256
 
254
257
  `receive` must stop when `signal` aborts. Yield deliveries in order. Throwing from `reply` means
255
- the reply was not accepted. Errors must not contain secrets.
258
+ the reply was not accepted. Errors must not contain secrets. `reply` may return
259
+ `{ questionRefused: "<reason>" }` when it accepted the reply but did not show its question
260
+ (section 7.1); the reason is cleaned and shown to the model.
256
261
 
257
262
  `describe` is optional. The `/channel-status` command shows the transport in use and the text the
258
263
  adapter returns. That text is for the person who runs the agent: it must not contain keys or
@@ -279,6 +284,47 @@ message text. A `describe` that throws is reported as one line; its error text i
279
284
  - A 2xx answer means accepted. Any other answer is reported to the model as a failure. The agent
280
285
  does not retry automatically.
281
286
 
287
+ ### 7.1 A question with the reply
288
+
289
+ The model asks the person something by adding `question` to its `reply` call. The reply carries it
290
+ unchanged after validation:
291
+
292
+ ```json
293
+ {
294
+ "type": "reply",
295
+ "conversationId": "c1",
296
+ "messageId": "r-7f3a2c10",
297
+ "replyTo": "m1",
298
+ "text": "Before I stop the test instance: which environment do you mean?",
299
+ "question": {
300
+ "text": "Which environment?",
301
+ "options": ["Test", "Staging", "Production"],
302
+ "allowText": true
303
+ },
304
+ "at": "2026-11-26T10:00:00.000Z"
305
+ }
306
+ ```
307
+
308
+ | Field | Required | Rule |
309
+ | ----------- | -------- | -------------------------------------------------------------------- |
310
+ | `text` | yes | One line, 1 to 300 characters after trimming, no control characters. |
311
+ | `options` | no | 1 to 6 distinct options, each one line of 1 to 80 characters. |
312
+ | `allowText` | no | `true`: the person may answer in their own words. |
313
+
314
+ A question needs `options`, `allowText: true`, or both. No other field is accepted. A reply without
315
+ `question` is unchanged: services that do not know the field keep working, and a service that does
316
+ not show questions may ignore it.
317
+
318
+ - The person's answer is not part of the reply: it arrives later as a new inbound `message` of the
319
+ same conversation, with the chosen option or the typed text. The model does not wait in the
320
+ `reply` call.
321
+ - The service may accept the reply and still not show its question (for example, another question
322
+ of the conversation still waits for an answer). It says so with a 2xx answer whose JSON body is
323
+ `{ "questionRefused": "<reason>" }`; a module adapter returns the same object. The model is told
324
+ `Reply sent, but its question was not shown: <reason>.`
325
+ - Oh My Pi's built-in `ask` tool is blocked: it would open a dialog in the terminal that nobody in
326
+ the chat can answer. The model is told to ask through `reply` with `question` instead.
327
+
282
328
  ## 8. Agent status (agent to service)
283
329
 
284
330
  ```json
@@ -404,7 +450,73 @@ made before it.
404
450
  two. Nothing is sent about a message after its reply or failure report. A use still `running` when
405
451
  that arrives has ended without a known outcome.
406
452
 
407
- ## 11. Security rules
453
+ ## 11. Reasoning (optional)
454
+
455
+ While the agent works on a message, omp-channel can tell the service what the model thinks, as it
456
+ is written. A service must not require these reports.
457
+
458
+ ```json
459
+ {
460
+ "type": "reasoning",
461
+ "conversationId": "c1",
462
+ "messageId": "r-3b7e90a1",
463
+ "replyTo": "m1",
464
+ "seq": 0,
465
+ "text": "The log shows a timeout, so I will look at the retry first.\n",
466
+ "final": false,
467
+ "at": "2026-11-27T10:00:01.000Z"
468
+ }
469
+ ```
470
+
471
+ | Field | Meaning |
472
+ | ----------- | ---------------------------------------------------------------------------- |
473
+ | `messageId` | Generated by the agent for each report, so a retried POST can be recognized. |
474
+ | `replyTo` | The `messageId` of the inbound message the agent is working on. |
475
+ | `seq` | 0 for the first piece of a message, then 1, 2 and so on. |
476
+ | `text` | At most 4000 characters. Empty only on a final report. |
477
+ | `final` | `true` on the last piece of a message. |
478
+ | `truncated` | `true`, present once the reasoning was cut at the size limit (see below). |
479
+
480
+ The pieces of one message, in `seq` order and joined as they are, make its reasoning. They keep
481
+ their line breaks and spaces. Two blocks of thinking are separated by a blank line. A block the model
482
+ marks as redacted is not reported.
483
+
484
+ **When they are sent.** Only when both are true: `reports.reasoning` is not `false` (it is `true` by
485
+ default), and the transport takes the report. Over HTTP the path `service.paths.reasoning` has no
486
+ default, so a service that does not configure it receives no new request. A custom adapter takes the
487
+ reports when it has the `reasoning` method. MCP push has no way back, so nothing is sent. A service
488
+ that does not want the text can refuse the calls: a refusal is logged once and not repeated for
489
+ that piece.
490
+
491
+ **What a report holds.** The thinking text of the model, as Oh My Pi streams it. Before sending, known
492
+ shapes of secrets and the home folder name are hidden (`[hidden]`, `~`), as in section 9, and control
493
+ characters are replaced with spaces. This is a known-shapes filter, not a guarantee: a secret in a
494
+ shape it does not know, or a quoted value with spaces, can pass. The model can write anything in its
495
+ thinking. Use `reports.reasoning: false` when that is not acceptable.
496
+
497
+ **Where a piece ends.** Text is gathered for 500 ms and sent in pieces. A piece ends at a space or a
498
+ line break, never after the name of a secret (`password:`), and never inside a private key that is
499
+ not closed yet: the next piece would carry the rest of it unhidden. A run of 4000 characters with no
500
+ space is hidden whole and the rest of that run is dropped.
501
+
502
+ **Which message.** The same as for activity (section 10): the newest unanswered message among those
503
+ of the last prompt that carried one. A prompt typed at the terminal ends it: its thinking is not
504
+ reported. Switching to another session ends it too.
505
+
506
+ **Limits.** At most 4000 characters in a report and 64 KiB for one message. Over 64 KiB the start is
507
+ kept, the rest is dropped and the last report has `truncated: true`. Reports leave one at a time, in
508
+ order, about twice a second. At most 100 wait to be sent; more are dropped. A report that takes more
509
+ than 5 seconds counts as refused. The agent never waits for a report, except that a reply or a
510
+ failure report waits up to 1 second for the reports made before it.
511
+
512
+ **The end.** When a message gets its reply or its failure report, what is left is sent at once, as
513
+ the last piece (`final: true`). Nothing is sent about the message after that, and a service should
514
+ refuse it.
515
+
516
+ **What a service can count on.** Delivery is best effort: a piece can be missing. A message that
517
+ has no `final` piece ended without one.
518
+
519
+ ## 12. Security rules
408
520
 
409
521
  - The service key is read from an environment variable named in the configuration
410
522
  (`service.keyEnv`), or from a file named by `<keyEnv>_FILE`. It is never written in the
@@ -418,14 +530,17 @@ that arrives has ended without a known outcome.
418
530
  - The error text of a failed turn is cleaned of known secret shapes before it is sent (section 9).
419
531
  - An activity report holds the tool name and the cleaned intent only, never arguments or results
420
532
  (section 10).
533
+ - A reasoning report holds the thinking text of the model with known secret shapes and the home
534
+ folder name hidden. It is the most revealing report: `reports.reasoning: false` keeps it on the
535
+ machine (section 11).
421
536
 
422
- ## 12. Versioning
537
+ ## 13. Versioning
423
538
 
424
539
  `PROTOCOL_VERSION` is `1`. Version 1 is alpha: fields may still change before the first stable
425
540
  release, and each change is recorded in CHANGELOG.md. A future incompatible change will use a
426
541
  new version number.
427
542
 
428
- ## 13. Not in this contract
543
+ ## 14. Not in this contract
429
544
 
430
545
  - Delivery of messages from the agent to a person without a reply to a message.
431
546
  - Attachments and other non-text content.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "omp-channel",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "description": "Oh My Pi extension that delivers messages from an external console into an agent session and sends replies back.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",