omp-channel 0.2.0 → 0.3.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.
package/dist/redact.d.ts CHANGED
@@ -4,8 +4,21 @@
4
4
  * `failures.includeReason: false` keeps the reason on the machine.
5
5
  */
6
6
  export declare const MAX_REASON_LENGTH = 500;
7
+ export declare const MAX_ACTIVITY_LENGTH = 240;
7
8
  /**
8
9
  * One line, secrets hidden, at most `MAX_REASON_LENGTH` characters. Undefined when nothing is
9
10
  * left. Secrets are hidden before the cut, so a cut never leaves part of one.
10
11
  */
11
12
  export declare function cleanReason(raw: string): string | undefined;
13
+ /**
14
+ * The same hiding for a longer text that keeps its lines: the answer a model wrote without using
15
+ * the reply tool. At most `maxLength` characters. Undefined when nothing is left.
16
+ */
17
+ export declare function cleanText(raw: string, maxLength: number): string | undefined;
18
+ /**
19
+ * The line of one tool use: the tool name and the intent stated for the call, on one line of at
20
+ * most `MAX_ACTIVITY_LENGTH` characters. The intent is free text, and some tools build it from
21
+ * their arguments, so every argument value quoted in it is left out, and so are secrets, paths and
22
+ * addresses. Known shapes and exact quotes only, not a guarantee.
23
+ */
24
+ export declare function activityText(toolName: string, intent: string | undefined, args: unknown): string;
package/dist/redact.js CHANGED
@@ -4,10 +4,20 @@
4
4
  * `failures.includeReason: false` keeps the reason on the machine.
5
5
  */
6
6
  export const MAX_REASON_LENGTH = 500;
7
+ export const MAX_ACTIVITY_LENGTH = 240;
8
+ const MAX_TOOL_NAME_LENGTH = 80;
9
+ /** Argument values shorter than this are not looked for in an intent: they are ordinary words. */
10
+ const MIN_ARGUMENT_LENGTH = 4;
11
+ /** The field of a tool call that holds the intent itself. */
12
+ const INTENT_ARGUMENT = "i";
13
+ const MAX_ARGUMENT_DEPTH = 4;
14
+ const MAX_ARGUMENT_VALUES = 200;
15
+ /** How much of an intent is read. */
16
+ const MAX_INTENT_READ = 4_000;
7
17
  const HIDDEN = "[hidden]";
18
+ /** A private key block, from its first line to its last one, or to the end of the text. */
19
+ const KEY_BLOCK = /-----BEGIN [A-Z0-9 ]*PRIVATE KEY-----[\s\S]*?(?:-----END [A-Z0-9 ]*PRIVATE KEY-----|$)/g;
8
20
  const SECRET_SHAPES = [
9
- // A private key block, from its first line.
10
- [/-----BEGIN [A-Z0-9 ]*PRIVATE KEY-----.*$/g, HIDDEN],
11
21
  // The credentials of an address (scheme://user:password@host): the host stays.
12
22
  [/\b([a-z][a-z0-9+.-]*:\/\/)[^\s/:@]*:[^\s/@]+@/gi, `$1${HIDDEN}@`],
13
23
  // The query of an address can carry keys.
@@ -40,26 +50,107 @@ const LONG_TOKEN = /[A-Za-z0-9_+=-]{32,}/g;
40
50
  * left. Secrets are hidden before the cut, so a cut never leaves part of one.
41
51
  */
42
52
  export function cleanReason(raw) {
43
- let text = oneLine(raw);
53
+ return cut(hideSecrets(oneLine(raw)), MAX_REASON_LENGTH);
54
+ }
55
+ /**
56
+ * The same hiding for a longer text that keeps its lines: the answer a model wrote without using
57
+ * the reply tool. At most `maxLength` characters. Undefined when nothing is left.
58
+ */
59
+ export function cleanText(raw, maxLength) {
60
+ return cut(hideSecrets(withoutControls(raw, "\n\t")).trim(), maxLength);
61
+ }
62
+ /**
63
+ * The line of one tool use: the tool name and the intent stated for the call, on one line of at
64
+ * most `MAX_ACTIVITY_LENGTH` characters. The intent is free text, and some tools build it from
65
+ * their arguments, so every argument value quoted in it is left out, and so are secrets, paths and
66
+ * addresses. Known shapes and exact quotes only, not a guarantee.
67
+ */
68
+ export function activityText(toolName, intent, args) {
69
+ const name = cut(hideSecrets(oneLine(toolName)), MAX_TOOL_NAME_LENGTH) ?? "tool";
70
+ const read = oneLine((intent ?? "").slice(0, MAX_INTENT_READ));
71
+ const said = read === "" ? "" : hidePaths(hideSecrets(withoutArguments(read, argumentTexts(args, read))));
72
+ // Nothing but placeholders and punctuation says nothing.
73
+ const words = said.replace(/\[(?:hidden|path)\]|…/g, "");
74
+ const line = /[\p{L}\p{N}]/u.test(words) ? `${name}: ${said}` : name;
75
+ return cut(line, MAX_ACTIVITY_LENGTH) ?? name;
76
+ }
77
+ /** The texts among the arguments of a call that the intent could quote, longest first. */
78
+ function argumentTexts(args, intent) {
79
+ const found = [];
80
+ const visit = (value, depth) => {
81
+ if (found.length >= MAX_ARGUMENT_VALUES) {
82
+ return;
83
+ }
84
+ if (typeof value === "string") {
85
+ // The content of a file, for one: far too long to be quoted, and not worth reading.
86
+ const text = value.length > 2 * intent.length + 100 ? "" : oneLine(value);
87
+ if (text.length >= MIN_ARGUMENT_LENGTH && text.length <= intent.length) {
88
+ found.push(text);
89
+ }
90
+ }
91
+ else if (typeof value === "object" && value !== null && depth < MAX_ARGUMENT_DEPTH) {
92
+ for (const [key, inner] of Object.entries(value)) {
93
+ if (depth > 0 || key !== INTENT_ARGUMENT) {
94
+ visit(inner, depth + 1);
95
+ }
96
+ }
97
+ }
98
+ };
99
+ visit(args, 0);
100
+ return found.sort((a, b) => b.length - a.length);
101
+ }
102
+ /** Replaces each argument quoted as whole words. */
103
+ function withoutArguments(text, values) {
104
+ let result = text;
105
+ for (const value of values) {
106
+ const literal = value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
107
+ result = result.replace(new RegExp(`(?<![\\p{L}\\p{N}])${literal}(?![\\p{L}\\p{N}])`, "giu"), "…");
108
+ }
109
+ return result;
110
+ }
111
+ /** Replaces the words that look like a path or an address, keeping the punctuation around them. */
112
+ function hidePaths(text) {
113
+ return text.replace(/\S+/g, (token) => {
114
+ const [, before = "", word = "", after = ""] = /^([("'`<{]*)(.*?)([)"'`>}.,:;!?]*)$/.exec(token) ?? [];
115
+ return looksLikePath(word) ? `${before}[path]${after}` : token;
116
+ });
117
+ }
118
+ function looksLikePath(word) {
119
+ return (
120
+ // An address, with its scheme.
121
+ /[a-z][a-z0-9+.-]*:\/\//i.test(word) ||
122
+ // From the root, the home folder or the current one, also after `=` or `:`.
123
+ /(?:^|[=:])(?:~|\.{1,2})?\/./.test(word) ||
124
+ word.includes("\\") ||
125
+ // Two folders, or a folder and a file name with an extension.
126
+ /\/.*\//.test(word) ||
127
+ /\/[^/]*\.[A-Za-z0-9]{1,8}$/.test(word));
128
+ }
129
+ function hideSecrets(raw) {
130
+ let text = raw.replace(KEY_BLOCK, HIDDEN);
44
131
  for (const [pattern, replacement] of SECRET_SHAPES) {
45
132
  text = text.replace(pattern, replacement);
46
133
  }
47
- text = text.replace(LONG_TOKEN, (token) => /[A-Z]/.test(token) && /[a-z]/.test(token) && /\d/.test(token) ? HIDDEN : token);
134
+ return text.replace(LONG_TOKEN, (token) => /[A-Z]/.test(token) && /[a-z]/.test(token) && /\d/.test(token) ? HIDDEN : token);
135
+ }
136
+ function cut(text, maxLength) {
48
137
  const symbols = [...text];
49
138
  if (symbols.length === 0) {
50
139
  return undefined;
51
140
  }
52
- return symbols.length <= MAX_REASON_LENGTH
53
- ? text
54
- : `${symbols.slice(0, MAX_REASON_LENGTH - 1).join("")}…`;
141
+ return symbols.length <= maxLength ? text : `${symbols.slice(0, maxLength - 1).join("")}…`;
55
142
  }
56
143
  function oneLine(text) {
144
+ return withoutControls(text, "").replace(/\s+/g, " ").trim();
145
+ }
146
+ /** Control characters become spaces, except those in `keep`. */
147
+ function withoutControls(text, keep) {
57
148
  let result = "";
58
149
  for (const symbol of text) {
59
150
  const code = symbol.codePointAt(0) ?? 0;
60
151
  const control = code < 32 || (code >= 127 && code <= 159) || code === 0x2028 || code === 0x2029;
61
- result += control ? " " : symbol;
152
+ result += control && !keep.includes(symbol) ? " " : symbol;
62
153
  }
63
- return result.replace(/\s+/g, " ").trim();
154
+ return result;
64
155
  }
65
156
  //# sourceMappingURL=redact.js.map
@@ -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;AAErC,MAAM,MAAM,GAAG,UAAU,CAAC;AAE1B,MAAM,a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C;AAChB,CAAC"}
package/dist/turn.d.ts CHANGED
@@ -5,20 +5,35 @@
5
5
  export interface RunEnd {
6
6
  /** True when Oh My Pi continues the run on its own (a retry, for example). */
7
7
  readonly willContinue?: boolean | undefined;
8
+ /** True when background work that will continue the run is still going. */
9
+ readonly awaitingAsyncWork?: boolean | undefined;
8
10
  /** The session messages when the run ended. */
9
11
  readonly messages?: readonly unknown[] | undefined;
10
12
  }
11
- export interface FailedRun {
12
- /** The error the model provider reported, as it came. Clean it before it leaves the machine. */
13
- readonly reason: string | undefined;
14
- /** Ids of the channel messages the failed work was answering, oldest first. */
13
+ /** Fixed texts a service receives when there is no answer of the model to send. */
14
+ export declare const NO_REPLY_REASON = "The agent finished without sending a reply";
15
+ export declare const STOPPED_REASON = "The turn was stopped before the agent answered";
16
+ export declare const INCOMPLETE_REASON = "The agent stopped before finishing its answer";
17
+ /**
18
+ * A stretch of a run that ends with one outcome, and the channel messages it was answering.
19
+ * `completed`: the model finished an answer (`text`, which may be missing). `failed`: a model
20
+ * error. `stopped`: aborted, or ended before an answer.
21
+ */
22
+ export interface Segment {
23
+ /** Ids of the channel messages this stretch was answering, oldest first. */
15
24
  readonly messageIds: readonly string[];
25
+ readonly outcome: "completed" | "failed" | "stopped";
26
+ /** Why there is no answer. A model error comes as it is: clean it before it is sent. */
27
+ readonly reason: string | undefined;
28
+ /** The text the model ended its answer with, as it came: clean it before it is sent. */
29
+ readonly text: string | undefined;
16
30
  }
17
31
  /**
18
- * The failure of a run that ended in a model error, or undefined for every other end: a run that
19
- * goes on, a normal answer, an abort, or a run without any channel message.
20
- *
21
- * The messages looked at are those after the last completed answer: an older message that the
22
- * model finished with is not blamed for a later error.
32
+ * The channel messages of a finished run, grouped by the answer that closed them. Empty for a run
33
+ * that Oh My Pi continues (a retry, or background work that has not ended in an error) and for a
34
+ * run without channel messages. The messages are the whole session, so the caller drops those
35
+ * that already have a reply or a report.
23
36
  */
24
- export declare function failedRun(end: RunEnd): FailedRun | undefined;
37
+ export declare function segmentsOf(end: RunEnd): Segment[];
38
+ /** The text parts of a message. Thinking and tool calls are not text. */
39
+ export declare function textsOf(content: unknown): string[];
package/dist/turn.js CHANGED
@@ -1,49 +1,66 @@
1
1
  import { messageIdsIn } from "./protocol.js";
2
+ /** Fixed texts a service receives when there is no answer of the model to send. */
3
+ export const NO_REPLY_REASON = "The agent finished without sending a reply";
4
+ export const STOPPED_REASON = "The turn was stopped before the agent answered";
5
+ export const INCOMPLETE_REASON = "The agent stopped before finishing its answer";
2
6
  /**
3
- * The failure of a run that ended in a model error, or undefined for every other end: a run that
4
- * goes on, a normal answer, an abort, or a run without any channel message.
5
- *
6
- * The messages looked at are those after the last completed answer: an older message that the
7
- * model finished with is not blamed for a later error.
7
+ * The channel messages of a finished run, grouped by the answer that closed them. Empty for a run
8
+ * that Oh My Pi continues (a retry, or background work that has not ended in an error) and for a
9
+ * run without channel messages. The messages are the whole session, so the caller drops those
10
+ * that already have a reply or a report.
8
11
  */
9
- export function failedRun(end) {
12
+ export function segmentsOf(end) {
10
13
  if (end.willContinue === true) {
11
- return undefined;
12
- }
13
- const messages = (end.messages ?? []).filter(isRecord);
14
- let last = messages.length - 1;
15
- while (last >= 0 && messages[last]?.role !== "assistant") {
16
- last -= 1;
17
- }
18
- const failed = messages[last];
19
- if (failed === undefined || failed.stopReason !== "error") {
20
- return undefined;
21
- }
22
- const ids = [];
23
- for (let index = last - 1; index >= 0; index -= 1) {
24
- const message = messages[index];
25
- if (message === undefined) {
26
- continue;
14
+ return [];
15
+ }
16
+ const segments = [];
17
+ let ids = [];
18
+ // The last assistant message after the last completed answer and the last message to answer.
19
+ let last;
20
+ for (const message of (end.messages ?? []).filter(isRecord)) {
21
+ if (message.role === "user" || message.role === "developer") {
22
+ ids.push(...textsOf(message.content).flatMap(messageIdsIn));
23
+ // An end seen before this message says nothing about it.
24
+ last = undefined;
27
25
  }
28
- if (message.role === "assistant") {
26
+ else if (message.role === "assistant") {
29
27
  if (message.stopReason === "stop" || message.stopReason === "length") {
30
- break;
28
+ const text = textsOf(message.content).join("\n").trim();
29
+ add(segments, ids, "completed", undefined, text);
30
+ ids = [];
31
+ last = undefined;
32
+ }
33
+ else {
34
+ last = message;
31
35
  }
32
- continue;
33
- }
34
- if (message.role === "user" || message.role === "developer") {
35
- ids.unshift(...textsOf(message.content).flatMap(messageIdsIn));
36
36
  }
37
37
  }
38
- if (ids.length === 0) {
39
- return undefined;
38
+ if (last?.stopReason === "error") {
39
+ const reason = typeof last.errorMessage === "string" ? last.errorMessage : undefined;
40
+ add(segments, ids, "failed", reason, "");
41
+ }
42
+ else {
43
+ const aborted = last === undefined || last.stopReason === "aborted";
44
+ add(segments, ids, "stopped", aborted ? STOPPED_REASON : INCOMPLETE_REASON, "");
45
+ }
46
+ // Background work will continue the run: only an error is already final.
47
+ if (end.awaitingAsyncWork === true && segments.at(-1)?.outcome !== "failed") {
48
+ return [];
49
+ }
50
+ return segments;
51
+ }
52
+ function add(segments, ids, outcome, reason, text) {
53
+ if (ids.length > 0) {
54
+ segments.push({
55
+ messageIds: [...new Set(ids)],
56
+ outcome,
57
+ reason,
58
+ text: text === "" ? undefined : text,
59
+ });
40
60
  }
41
- return {
42
- reason: typeof failed.errorMessage === "string" ? failed.errorMessage : undefined,
43
- messageIds: [...new Set(ids)],
44
- };
45
61
  }
46
- function textsOf(content) {
62
+ /** The text parts of a message. Thinking and tool calls are not text. */
63
+ export function textsOf(content) {
47
64
  if (typeof content === "string") {
48
65
  return [content];
49
66
  }
@@ -52,7 +69,9 @@ function textsOf(content) {
52
69
  }
53
70
  return content
54
71
  .filter(isRecord)
55
- .flatMap((part) => (typeof part.text === "string" ? [part.text] : []));
72
+ .flatMap((part) => (part.type === undefined || part.type === "text") && typeof part.text === "string"
73
+ ? [part.text]
74
+ : []);
56
75
  }
57
76
  function isRecord(value) {
58
77
  return typeof value === "object" && value !== null && !Array.isArray(value);
package/dist/turn.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"turn.js","sour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AgB;IACtC,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAChC,OAAO,CAAC,OAAO,CAAC,CAAC;IACnB,CAAC;IACD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QAC5B,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,OAAO,OAAO;SACX,MAAM,CAAC,QAAQ,CAAC;SAChB,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAChB,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,CAAC,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ;QAChF,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;QACb,CAAC,CAAC,EAAE,CACP,CAAC;AACN,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC"}
package/docs/protocol.md CHANGED
@@ -19,6 +19,7 @@ The machine-readable schemas are in [`schema/`](https://github.com/tommasomarchi
19
19
  | `outbound-reply.schema.json` | a reply the agent posts to the service |
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
+ | `activity.schema.json` | a tool the agent uses for a message (optional report) |
22
23
  | `config.schema.json` | the omp-channel configuration file |
23
24
 
24
25
  The TypeScript module `src/protocol.ts` implements the same rules. Both must change together.
@@ -130,6 +131,7 @@ Paths are relative to `service.url` and configurable in `service.paths`. Default
130
131
  | Reply | `POST /replies` | outbound reply (section 7) |
131
132
  | Status | `POST /status` | agent status (section 8) |
132
133
  | Failure | `POST /failures` | failed turn (section 9) |
134
+ | Activity | no default path | activity (section 10) |
133
135
 
134
136
  All calls carry `Authorization: Bearer <key>`. A non-2xx answer is an error. The key is never
135
137
  included in a log line, an error message or a tool result.
@@ -216,6 +218,7 @@ interface ChannelAdapter {
216
218
  ack?(deliveryId: string): Promise<void>; // after admission
217
219
  status?(status: OutboundStatus): Promise<void>; // best effort
218
220
  failure?(failure: OutboundFailure): Promise<void>; // a message got no answer (section 9)
221
+ activity?(activity: OutboundActivity): Promise<void>; // a tool in use (section 10)
219
222
  interrupt?(conversationId: string): Promise<void>; // after an interrupt is applied
220
223
  close?(conversationId: string): Promise<void>; // after a close is applied
221
224
  describe?(): Promise<string> | string; // plain-text state for the /channel-status command
@@ -266,10 +269,28 @@ that Oh My Pi continues on its own (a retry of a model request, for example) has
266
269
  state stays `working`. Status is best effort: a failed report is logged and not retried. Status is
267
270
  not part of the acknowledgement logic.
268
271
 
269
- ## 9. Failed turn (agent to service)
272
+ ## 9. No message is left waiting
270
273
 
271
- A turn can end in an error, for example because the model provider refuses the request. The agent
272
- then answers nothing, so the service is told:
274
+ Every message the agent took ends with exactly one outcome that the service receives: a `reply`
275
+ (section 6) or a `failure`.
276
+
277
+ | What happens | What the service receives |
278
+ | ------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- |
279
+ | The model calls the `reply` tool | that reply |
280
+ | The run ends with an answer and no `reply` call | the final text of the model, as a reply |
281
+ | The same, with `replies.fromFinalText: false` or no text | `failure`: `The agent finished without sending a reply` |
282
+ | A model error | `failure` with the error text |
283
+ | The turn is aborted, or ends before an answer | `failure`: `The turn was stopped before the agent answered` or `The agent stopped before finishing its answer` |
284
+ | The service refuses the final text, also after two more tries | `failure`: `The agent answered, but the answer could not be delivered` |
285
+ | One answer covers several messages | the answer for the newest, `Answered together with a later message.` as the reply of each older one |
286
+ | A new, resumed or forked session while a message is open | `failure`: `The agent moved to another session before it answered` |
287
+ | Oh My Pi closes while a message is open | `failure`: `The agent was closed before it answered` (one attempt) |
288
+ | Oh My Pi retries, or background work will continue the run | nothing yet |
289
+
290
+ A process that is killed, or a machine that loses power or network for good, sends nothing: a
291
+ service should show that the agent is not connected.
292
+
293
+ The `failure` event:
273
294
 
274
295
  ```json
275
296
  {
@@ -284,28 +305,78 @@ then answers nothing, so the service is told:
284
305
 
285
306
  - One report for each unanswered message: `replyTo` is its `messageId`. `messageId` is generated
286
307
  by the agent for each report.
287
- - Sent only when the run is over. Oh My Pi retries some errors by itself; while it does, nothing is
288
- reported.
289
- - Only a model error is reported. An aborted turn (an interrupt from the service, or from the
290
- person at the terminal) is not.
291
- - A message that already got a reply is never reported. The failed turn blames only the messages
292
- it took after the last completed answer.
293
- - `reason` is optional text for a person: one line, at most 500 characters. Common shapes of
294
- secrets (tokens, credentials in headers and addresses) and the name of the home folder are
295
- hidden before it is sent. The hiding covers known shapes and is no guarantee: set
296
- `failures.includeReason` to `false` to send no text at all.
297
- - The report is best effort. A refused report is logged and sent again only if a later turn fails
298
- for the same message.
299
- - A reply for the same message is still accepted afterwards, for example when a later turn
300
- succeeds. A service that has shown the failure decides what to do with it.
308
+ - A message that already got a reply is never reported.
309
+ - `reason` is optional text for a person: one line, at most 500 characters.
310
+ `failures.includeReason: false` sends no reason.
311
+ - The final text sent as a reply is the text of the last answer only, never the thinking or a tool
312
+ result. It keeps its lines and is cut at `limits.maxTextLength`.
313
+ - In both, common shapes of secrets (tokens, credentials in headers and addresses) and the name of
314
+ the home folder are hidden before sending. The hiding covers known shapes and is no guarantee.
315
+ - A refused reply or report is tried again after 1 and 5 seconds. A message that still could not
316
+ be closed is tried again when the next run ends.
317
+ - A reply for the same message is still accepted afterwards. A service that has shown the failure
318
+ decides what to do with it.
301
319
  - A transport without the `failure` hook only logs the event. Over MCP push there is no way back
302
320
  to the service, so nothing is sent.
303
321
 
304
- ## 10. Activity (optional, not emitted in version 1)
322
+ ## 10. Activity (optional)
323
+
324
+ While the agent works on a message, omp-channel can tell the service which tools it uses: one
325
+ report when a tool starts and one when it ends. A service must not require these reports.
326
+
327
+ ```json
328
+ {
329
+ "type": "activity",
330
+ "conversationId": "c1",
331
+ "messageId": "a-9d02c7e4",
332
+ "replyTo": "m1",
333
+ "activityId": "t-51be",
334
+ "state": "running",
335
+ "text": "read: Reading the server log",
336
+ "at": "2026-11-26T10:00:00.000Z"
337
+ }
338
+ ```
305
339
 
306
- The protocol reserves an optional `activity` report (for example, a tool started or finished)
307
- for showing progress to the service. Version 1 of omp-channel does not emit it. A service must
308
- not require it.
340
+ | Field | Meaning |
341
+ | ------------ | -------------------------------------------------------------------------------- |
342
+ | `messageId` | Generated by the agent for each report. |
343
+ | `replyTo` | The `messageId` of the inbound message the agent is working on. |
344
+ | `activityId` | The same for the two reports about one use of a tool. Generated by the agent. |
345
+ | `state` | `running` when the tool starts, then `done` or `failed`. |
346
+ | `text` | The tool name, then `: ` and the intent of the call when there is one. One line. |
347
+
348
+ **When they are sent.** Only when both are true: `reports.activity` is not `false` (it is `true` by
349
+ default), and the transport takes the report. Over HTTP the path `service.paths.activity` has no
350
+ default, so a service that does not configure it receives no new request. A custom adapter takes
351
+ the reports when it has the `activity` method. MCP push has no way back, so nothing is sent.
352
+
353
+ **What a report holds.** The tool name and the intent that Oh My Pi states for the call. Oh My Pi
354
+ 19.2.1 asks the model for intents in its terminal interface by default, and not in print, RPC, ACP
355
+ or SDK processes unless its setting `tools.intentTracing` is on: without an intent the line is the
356
+ tool name alone. The arguments and the result of the tool are never sent. The intent is free text written by the model,
357
+ and some tools build it from their arguments, so before sending:
358
+
359
+ - every argument value quoted in it as whole words (4 characters or more) is replaced with `…`;
360
+ - common shapes of secrets and the home folder name are hidden (`[hidden]`), as in section 9;
361
+ - words that look like a path or an address become `[path]`;
362
+ - the line is cut at 240 characters.
363
+
364
+ These are known shapes and exact quotes, not a guarantee: an intent can still describe a command or
365
+ name a file in its own words. `reports.activity: false` keeps all of it on the machine.
366
+
367
+ **Which message.** The newest unanswered message among those of the last prompt that carried one.
368
+ A prompt typed at the terminal ends it: the tools used for that prompt are not reported. Switching
369
+ to another session ends it too. The `reply` tool is not reported.
370
+
371
+ **Limits.** At most 200 tool uses for one message. Reports leave one at a time, in order. At most
372
+ 100 wait to be sent; more are dropped. A report that takes more than 5 seconds counts as refused.
373
+ A refused report is not sent again, and is logged once until a report is accepted. The agent never
374
+ waits for a report, except that a reply or a failure report waits up to 1 second for the reports
375
+ made before it.
376
+
377
+ **What a service can count on.** Delivery is best effort: a report can be missing, either of the
378
+ two. Nothing is sent about a message after its reply or failure report. A use still `running` when
379
+ that arrives has ended without a known outcome.
309
380
 
310
381
  ## 11. Security rules
311
382
 
@@ -319,6 +390,8 @@ not require it.
319
390
  says so, and angle brackets are escaped so the text cannot close the envelope.
320
391
  - Inbound events are validated before use. Unknown fields and out-of-range values are rejected.
321
392
  - The error text of a failed turn is cleaned of known secret shapes before it is sent (section 9).
393
+ - An activity report holds the tool name and the cleaned intent only, never arguments or results
394
+ (section 10).
322
395
 
323
396
  ## 12. Versioning
324
397
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "omp-channel",
3
- "version": "0.2.0",
3
+ "version": "0.3.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",
@@ -0,0 +1,50 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://example.com/omp-channel/schema/activity.schema.json",
4
+ "title": "Activity (agent to service)",
5
+ "type": "object",
6
+ "additionalProperties": false,
7
+ "required": [
8
+ "type",
9
+ "conversationId",
10
+ "messageId",
11
+ "replyTo",
12
+ "activityId",
13
+ "state",
14
+ "text",
15
+ "at"
16
+ ],
17
+ "properties": {
18
+ "type": { "const": "activity" },
19
+ "conversationId": {
20
+ "type": "string",
21
+ "minLength": 1,
22
+ "maxLength": 128,
23
+ "pattern": "^[A-Za-z0-9._:-]+$"
24
+ },
25
+ "messageId": {
26
+ "type": "string",
27
+ "minLength": 1,
28
+ "maxLength": 128,
29
+ "pattern": "^[A-Za-z0-9._:-]+$"
30
+ },
31
+ "replyTo": {
32
+ "type": "string",
33
+ "minLength": 1,
34
+ "maxLength": 128,
35
+ "pattern": "^[A-Za-z0-9._:-]+$"
36
+ },
37
+ "activityId": {
38
+ "type": "string",
39
+ "minLength": 1,
40
+ "maxLength": 128,
41
+ "pattern": "^[A-Za-z0-9._:-]+$"
42
+ },
43
+ "state": { "type": "string", "enum": ["running", "done", "failed"] },
44
+ "text": { "type": "string", "minLength": 1, "maxLength": 240 },
45
+ "at": {
46
+ "type": "string",
47
+ "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(Z|[+-]\\d{2}:\\d{2})$"
48
+ }
49
+ }
50
+ }
@@ -67,6 +67,11 @@
67
67
  "type": "string",
68
68
  "pattern": "^/",
69
69
  "default": "/failures"
70
+ },
71
+ "activity": {
72
+ "description": "Where activity reports are posted. No default: without it none are sent.",
73
+ "type": "string",
74
+ "pattern": "^/"
70
75
  }
71
76
  },
72
77
  "default": {}
@@ -149,6 +154,32 @@
149
154
  },
150
155
  "default": {}
151
156
  },
157
+ "replies": {
158
+ "description": "How a message gets its reply when the model does not use the reply tool.",
159
+ "type": "object",
160
+ "additionalProperties": false,
161
+ "properties": {
162
+ "fromFinalText": {
163
+ "description": "Send the final text of the model, with secrets hidden, as the reply.",
164
+ "type": "boolean",
165
+ "default": true
166
+ }
167
+ },
168
+ "default": {}
169
+ },
170
+ "reports": {
171
+ "description": "Optional reports about the work on a message.",
172
+ "type": "object",
173
+ "additionalProperties": false,
174
+ "properties": {
175
+ "activity": {
176
+ "description": "Report the tools used for a message (name and intent, never arguments or results), when the transport takes it.",
177
+ "type": "boolean",
178
+ "default": true
179
+ }
180
+ },
181
+ "default": {}
182
+ },
152
183
  "adapterModule": {
153
184
  "description": "Path (relative to the working directory) of a JavaScript module whose default export implements ChannelAdapter. Replaces the HTTP service transport.",
154
185
  "type": "string",