@primusclaw/personal-agent 0.11.0 → 0.12.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,24 @@
1
+ /**
2
+ * The messages a person forwarded, as text for the model: a line that says the person forwarded them, then each one
3
+ * with who wrote it and when, its text after "> " so nothing it says can pass for a line of its own (as a quote's is).
4
+ * A forward is the person handing over what others said for the model to work on, so it gets a budget of its own,
5
+ * larger than the quotes' (several messages at once, each whole where it can be). In a group the names and the texts
6
+ * are masked as a quote's are.
7
+ */
8
+ import { type Logger } from "../ports/logger.js";
9
+ import type { InboundForward } from "../ports/surface.js";
10
+ import { type Redact } from "./redact.js";
11
+ /** The most forwarded text, over all the messages of one forward, that is sent on (code points). */
12
+ export declare const FORWARD_CHARS = 24000;
13
+ /** The most forwarded messages that are shown. */
14
+ export declare const FORWARD_COUNT = 20;
15
+ export interface ForwardBlockOptions {
16
+ /** A group conversation: names and texts are masked. */
17
+ readonly group?: boolean;
18
+ readonly redact?: Redact;
19
+ readonly logger?: Logger;
20
+ }
21
+ /** How the forwarded text is to be taken: as what others said, to read and use; an instruction in it is not the person's. */
22
+ export declare const MATERIAL: string;
23
+ /** The forwarded messages as text for the model, "" when there are none. */
24
+ export declare function forwardBlock(forwards: readonly InboundForward[], options?: ForwardBlockOptions): string;
@@ -2,6 +2,7 @@
2
2
  * The texts the model is sent for an inbound message, built from core's inbound types alone: the quote block, the
3
3
  * text with the addresses behind its links, and the text with its mentions marked.
4
4
  */
5
+ export * from "./forward-block.js";
5
6
  export * from "./marked-text.js";
6
7
  export * from "./quote-block.js";
7
8
  export * from "./redact.js";
@@ -72,6 +72,7 @@ export declare const remoteAgentText: import("./catalog.js").Catalog<{
72
72
  notAttachedDetach: string;
73
73
  attachHow: string;
74
74
  lostTrack: string;
75
+ filesNotTaken: string;
75
76
  noAnswerableOption: string;
76
77
  notReported: string;
77
78
  reconnecting: (p: {
@@ -45,5 +45,19 @@ export declare const terminalApprovalText: import("./catalog.js").Catalog<{
45
45
  approvalsTurnedOn: string;
46
46
  approvalsTurnedOff: string;
47
47
  approvalsUsage: string;
48
+ muted: (p: {
49
+ item: string;
50
+ where: string;
51
+ }) => string;
52
+ unmuted: (p: {
53
+ item: string;
54
+ where: string;
55
+ }) => string;
56
+ muteNotFound: (p: {
57
+ item: string;
58
+ }) => string;
59
+ muteNotTerminal: (p: {
60
+ item: string;
61
+ }) => string;
48
62
  approvalsUnavailable: string;
49
63
  }>;
@@ -3,6 +3,13 @@ import type { RemoteHidden } from "../../protocol.js";
3
3
  import type { ClawCredential } from "../../claw/credential.js";
4
4
  import type { SseEvent } from "../../claw/model.js";
5
5
  import type { RemoteConnector, RemoteEventRow, RemotePairing, RemoteSession, RemoteSetup } from "../../claw/remote.js";
6
+ /** What Claw stored for a muted (or unmuted) terminal conversation (`PUT /v1/remote-agents/approvals/mutes`). */
7
+ export interface TerminalMute {
8
+ readonly item: number;
9
+ readonly muted: boolean;
10
+ readonly machine: string;
11
+ readonly title: string;
12
+ }
6
13
  /** What a remote session starts with. */
7
14
  export interface NewRemoteSession {
8
15
  readonly connectorId: string;
@@ -43,6 +50,11 @@ export interface ClawRemoteAgentsPort {
43
50
  approvals(key: ClawCredential): Promise<boolean>;
44
51
  /** Turn them on or off (`PUT /approvals`); answers the setting as Claw stored it. */
45
52
  setApprovals(key: ClawCredential, enabled: boolean): Promise<boolean>;
53
+ /**
54
+ * Mute (or unmute) one conversation open in a terminal, named by its work item (`#<item>`): nothing it asks, waits for or finishes
55
+ * is pushed while muted (`PUT /approvals/mutes`). Answers what Claw stored, and the machine and conversation it names.
56
+ */
57
+ muteTerminal(key: ClawCredential, item: number, muted: boolean): Promise<TerminalMute>;
46
58
  createSession(key: ClawCredential, session: NewRemoteSession): Promise<RemoteSession>;
47
59
  sessions(key: ClawCredential): Promise<RemoteSession[]>;
48
60
  session(key: ClawCredential, sessionId: string): Promise<RemoteSession>;
@@ -16,6 +16,14 @@ export interface MetricsPort {
16
16
  limited(reason: string): void;
17
17
  /** `count` files a person sent did not reach Claw on `path` (assistant | session | remote_agent | review | unreadable). */
18
18
  filesDropped(path: string, count?: number): void;
19
+ /**
20
+ * One delivery probe (a surface's synthetic message through its own queues): milliseconds from its sending to the
21
+ * worker's answer queued, and to that answer's round trip back (null: it did not come back in time). Optional: a
22
+ * port of one's own without it does not count them.
23
+ */
24
+ probed?(feedbackMs: number, replyMs: number | null): void;
25
+ /** A receiver of the surface's inbound queue whose call on the broker hung was dropped and taken again (optional). */
26
+ inboundRearmed?(): void;
19
27
  }
20
28
  /** Metrics that go nowhere: the default where a caller passes none. */
21
29
  export declare const noMetrics: MetricsPort;
@@ -81,6 +81,25 @@ export interface InboundQuote {
81
81
  */
82
82
  readonly source: "entity" | "html" | "placeholder";
83
83
  }
84
+ /**
85
+ * A message someone else wrote that the person forwarded into this chat (Teams' Forward), or one of several they
86
+ * forwarded at once. What it says is never part of the person's own words.
87
+ */
88
+ export interface InboundForward {
89
+ /** The channel's id of the original message ("" when not said). */
90
+ readonly messageId: string;
91
+ /** Who wrote it ("" when the channel did not say). */
92
+ readonly author: string;
93
+ /**
94
+ * What it says. An image it showed stands where it stood: `[image-<n>]` when it is file n of the message's files (the
95
+ * name it is passed on under starts so), `[image not passed on]` when it could not be.
96
+ */
97
+ readonly text: string;
98
+ /** When it was written, as the channel said it ("" when not said). */
99
+ readonly sentAt: string;
100
+ /** Where the adapter read it (for a log line, never the text): the message's HTML, or a forward reference. */
101
+ readonly source: "html" | "reference";
102
+ }
84
103
  /** Someone the message @mentions (never the bot itself: the adapter removes its own mention). */
85
104
  export interface InboundMention {
86
105
  /** The channel's id of the person (Teams: "29:..."). */
@@ -127,6 +146,9 @@ export interface InboundMessage extends InboundBase {
127
146
  readonly mentions: readonly InboundMention[];
128
147
  readonly links: readonly InboundLink[];
129
148
  readonly quotes: readonly InboundQuote[];
149
+ /** The messages the person forwarded with this one, in the order the channel gave them (absent: none). */
150
+ readonly forwards?: readonly InboundForward[];
151
+ /** Includes the images of the forwarded messages that the channel gave a way to fetch. */
130
152
  readonly files: readonly InboundFile[];
131
153
  /**
132
154
  * The names of attachments the channel gave no way to fetch (a file shared as a link), told back to the person
@@ -13,6 +13,10 @@ export declare const REMOTE_AGENT_LIMITS: {
13
13
  readonly maxCapabilitiesBytes: number;
14
14
  /** Bytes of one prompt. */
15
15
  readonly maxPromptBytes: number;
16
+ /** Files one prompt may carry (`prompt.files`). */
17
+ readonly maxPromptFiles: 10;
18
+ /** Bytes of all the files of one prompt together, decoded (base64 makes them a third larger on the wire). */
19
+ readonly maxPromptFileBytes: number;
16
20
  /** Commands one user may issue per minute, across all connectors. */
17
21
  readonly commandsPerMinute: 60;
18
22
  };
@@ -66,6 +70,15 @@ export declare function connectorVersionStatus(version: string | null | undefine
66
70
  export declare const REMOTE_EVENT_PERMISSION_REQUEST = "permissionRequest";
67
71
  export declare const REMOTE_EVENT_PERMISSION_RESOLVED = "permission_resolved";
68
72
  export declare const REMOTE_EVENT_SESSION_CLOSED = "session_closed";
73
+ /**
74
+ * A turn of a conversation open in a terminal ended while nobody was at that terminal, posted on the conversation's terminal-hook
75
+ * session (`origin` "terminal_hook") by its connector: `{ref, outcome: "done" | "error", error?, message, agent, cwd, ended_at,
76
+ * away_ms}`. `message` is the end of what the agent last said (untrusted text); `error` names why a turn that failed did
77
+ * (Claude Code's `StopFailure` reason, such as `rate_limit`). The connector posts it only once the terminal has had no input for a
78
+ * minute after the turn ended, and never while a chat follows the conversation; Claw tells the owner, unless they turned the
79
+ * terminal pushes off or muted that conversation.
80
+ */
81
+ export declare const REMOTE_EVENT_TERMINAL_TURN_END = "terminal_turn_end";
69
82
  /**
70
83
  * What the person sent a session (a `prompt` command), written by Claw itself when it queues the prompt: `{text, cmd_id, cmd_seq,
71
84
  * client, by: "claw"}` with a negative `seq`. An agent's events carry only its own side, so without it a window opened on the
@@ -225,6 +238,11 @@ export declare function parseTerminalSessionOpen(body: unknown): Parsed<RemoteTe
225
238
  export declare function parseApprovalsSetting(body: unknown): Parsed<{
226
239
  enabled: boolean;
227
240
  }>;
241
+ /** `PUT /v1/remote-agents/approvals/mutes`: mute (or unmute) the conversation behind work item `#item`, one open in a terminal. */
242
+ export declare function parseTerminalMute(body: unknown): Parsed<{
243
+ item: number;
244
+ muted: boolean;
245
+ }>;
228
246
  /**
229
247
  * Hiding conversations of a machine from its owner's lists (`POST /v1/remote-agents/connectors/:cid/hidden`), and the
230
248
  * listing that leaves them out (`GET /v1/remote-agents/connectors`, `?hidden=include` to list them too). Nothing on the
@@ -292,6 +310,21 @@ export interface RemoteCommandSpec {
292
310
  /** What the audit trail keeps. Never the text a user typed. */
293
311
  audit(payload: Record<string, unknown>): Record<string, unknown>;
294
312
  }
313
+ /** A file a prompt carries, as the connector receives it. */
314
+ export interface RemotePromptFile {
315
+ /** One safe path component: letters, digits, `._ -`, no leading dot, at most 100 characters. */
316
+ name: string;
317
+ media_type: string;
318
+ /** The bytes, base64. */
319
+ data: string;
320
+ }
321
+ /**
322
+ * The files a prompt carries (`files`, optional): at most {@link REMOTE_AGENT_LIMITS.maxPromptFiles}, each a safe name, a
323
+ * media type and its bytes in base64, all together at most {@link REMOTE_AGENT_LIMITS.maxPromptFileBytes} decoded, no two
324
+ * with one name (compared without case). A connector that says it can (the agent capability `prompt_files`) saves them on its machine and names
325
+ * where in the prompt; Claw keeps them only while the command waits to be delivered, never in the session's events.
326
+ */
327
+ export declare function parsePromptFiles(raw: unknown): Parsed<RemotePromptFile[]>;
295
328
  export declare const REMOTE_COMMANDS: Record<RemoteCommandType, RemoteCommandSpec>;
296
329
  export declare function isRemoteCommandType(v: unknown): v is RemoteCommandType;
297
330
  /** One server-sent-events frame. `id` is omitted for frames a client must not resume from. */
@@ -13,6 +13,8 @@ export declare function agentRef(connector: Pick<Connector, "name">, agent: Pick
13
13
  export declare function agentRoots(agent: Agent): string[];
14
14
  /** The connector can take back a message that waits for its terminal without stopping anything (`withdraw`). */
15
15
  export declare function withdraws(agent: Agent | null | undefined): boolean;
16
+ /** The connector saves the files a prompt carries on its machine and names them in the prompt (`prompt_files`). */
17
+ export declare function takesFiles(agent: Agent | null | undefined): boolean;
16
18
  /** The connector can open a conversation that is open in a terminal read-only (`watch_live`). */
17
19
  export declare function watchesLive(agent: Agent): boolean;
18
20
  /** The connector types messages into the terminal that has this conversation open (a tmux pane of its user's). */
@@ -3,6 +3,7 @@ import type { CommandHandler, CommandRoute } from "../ports/routing.js";
3
3
  export declare class TerminalApprovalsCommand implements CommandHandler {
4
4
  private readonly claw;
5
5
  readonly name = "approvals";
6
- constructor(claw: Pick<ClawRemoteAgentsPort, "approvals" | "setApprovals">);
6
+ constructor(claw: Pick<ClawRemoteAgentsPort, "approvals" | "setApprovals" | "muteTerminal">);
7
7
  run(route: CommandRoute, args: string): Promise<boolean>;
8
+ private mute;
8
9
  }
@@ -1,4 +1,4 @@
1
- import { type Conversation } from "../ports/surface.js";
1
+ import { type Conversation, type FetchedFile } from "../ports/surface.js";
2
2
  import type { StatusBoard } from "./board.js";
3
3
  import type { RemoteContext } from "./context.js";
4
4
  import type { Provider } from "./ended.js";
@@ -22,7 +22,11 @@ export interface Prompt {
22
22
  readonly source: SentFrom;
23
23
  /** The message replies quoting this chat's session card. */
24
24
  readonly quotesWindow: boolean;
25
+ /** Files the machine saves and names in the prompt (its agent `takesFiles`). */
26
+ readonly files?: readonly FetchedFile[];
25
27
  }
28
+ /** `bytes` as base64 (the wire's `prompt.files[].data`). */
29
+ export declare function base64Of(bytes: Uint8Array): string;
26
30
  export declare class Prompts {
27
31
  private readonly ctx;
28
32
  private readonly state;
@@ -49,6 +53,12 @@ export declare class Prompts {
49
53
  * told why) when it did not go.
50
54
  */
51
55
  private send;
56
+ /**
57
+ * A Claw that knows no `files` field took the words and dropped the files unread: the person is told. A repeat of a
58
+ * prompt Claw already has (`duplicate`) says nothing: the first send's answer was where they were told, and a
59
+ * redelivered message is never told twice.
60
+ */
61
+ private filesTaken;
52
62
  private failure;
53
63
  private started;
54
64
  /**
@@ -28,6 +28,7 @@ export declare class RemoteAgents implements RemoteChat {
28
28
  private readonly machine;
29
29
  private readonly permissions;
30
30
  private readonly prompts;
31
+ private readonly ops;
31
32
  private readonly runner;
32
33
  private readonly ctx;
33
34
  constructor(context: RemoteContext);
@@ -54,6 +55,7 @@ export declare class RemoteAgents implements RemoteChat {
54
55
  chatContext(chatKey: string, credential: string): Promise<JsonObject | null>;
55
56
  private call;
56
57
  prompt(request: RemotePrompt): Promise<void>;
58
+ takesFiles(chatKey: string, credential: string): Promise<boolean>;
57
59
  /** `only`: a Stop card's turn; the press stops nothing once that turn is not the one running (see Prompts.stop). */
58
60
  stop(chat: UserRef, credential: string, conversation: Conversation, only?: RemoteTurn): Promise<boolean>;
59
61
  /** The turn this worker is watching for the chat now, if any (what a phone's Stop card is sent for). */
@@ -3,7 +3,7 @@ import type { JsonObject } from "../json.js";
3
3
  import type { KeyOwner } from "../plugins/identity-lookup.js";
4
4
  import type { Lang } from "../locales/lang.js";
5
5
  import type { GroupContextKept } from "../locales/transparency.js";
6
- import type { Conversation, InboundFile, InboundMessage, OutMessage, UserRef } from "../ports/surface.js";
6
+ import type { Conversation, FetchedFile, InboundFile, InboundMessage, OutMessage, UserRef } from "../ports/surface.js";
7
7
  /**
8
8
  * What the router asks of the features it hands messages to. Each is implemented by the feature's own module (the
9
9
  * assistant, remote agents, the turn engine, the review service, observing, notifications) and given to the router by
@@ -89,6 +89,8 @@ export interface RemotePrompt {
89
89
  readonly prompt: string;
90
90
  readonly conversation: Conversation;
91
91
  readonly provider: CredentialProvider;
92
+ /** Files the session's machine saves and names in the prompt (only where it `takesFiles`). */
93
+ readonly files?: readonly FetchedFile[];
92
94
  }
93
95
  export interface RemoteAgentCommand {
94
96
  readonly chat: UserRef;
@@ -104,6 +106,11 @@ export interface RemoteAgentCommand {
104
106
  export interface RemoteChat {
105
107
  readonly enabled: boolean;
106
108
  attached(chatKey: string): boolean;
109
+ /**
110
+ * The machine of the chat's session saves the files a prompt carries and names them in it (its agent says `prompt_files`);
111
+ * absent or false: a session gets text only.
112
+ */
113
+ takesFiles?(chatKey: string, credential: string): Promise<boolean>;
107
114
  /** The chat is the agent's window itself (direct chat). */
108
115
  direct(chatKey: string): boolean;
109
116
  windowMode(chatKey: string): "card" | "chat";
@@ -1,7 +1,7 @@
1
1
  import type { InboundMessage } from "../ports/surface.js";
2
2
  import type { Chat } from "./chat.js";
3
3
  import type { RouterContext } from "./context.js";
4
- import type { PersonalText } from "./personal-text.js";
4
+ import { type PersonalText } from "./personal-text.js";
5
5
  export interface GroupWords {
6
6
  readonly text: string;
7
7
  readonly quote: string;
@@ -1,8 +1,10 @@
1
- import type { InboundFile, InboundMessage } from "../ports/surface.js";
1
+ import type { FetchedFile, InboundFile, InboundMessage } from "../ports/surface.js";
2
2
  import type { Chat } from "./chat.js";
3
3
  import type { CommandTable } from "./command-table.js";
4
4
  import type { RouterContext } from "./context.js";
5
5
  import { type TurnStarter } from "./turn-start.js";
6
+ /** What a session is sent for files that came with no words (a prompt is never empty). */
7
+ export declare const FILES_ONLY = "The person sent the files below with no words.";
6
8
  /**
7
9
  * A 1:1 message that is not one of the chat's commands, as it goes on (the Python `Agent._text_of`, `_on_text`,
8
10
  * `_sent_on`, `_talks_to_agent`, `_session_control`, `_understand`, `_understood`, `_offer_github`, `_attachments`):
@@ -28,6 +30,14 @@ export declare class PersonalText {
28
30
  talksToAgent(message: InboundMessage): boolean;
29
31
  /** The files that go to Claw with a message; the person is told about the ones that do not, and they are counted. */
30
32
  attachments(message: InboundMessage, chat: Chat, elsewhere?: boolean): Promise<readonly InboundFile[]>;
33
+ /**
34
+ * The files of a message to the session `chatKey` is attached to (the 1:1 chat's, or a bound group's): text files inline
35
+ * after the person's words, in `room` bytes; other files to its machine where it takes them; the person told about the rest.
36
+ */
37
+ toSession(message: InboundMessage, chat: Chat, chatKey: string, key: string, room: number): Promise<{
38
+ section: string;
39
+ files: readonly FetchedFile[];
40
+ }>;
31
41
  /** What the chat is attached to, for the assistant (only where remote agents are on). */
32
42
  private attached;
33
43
  /** A 1:1 message that is no command, as it goes on to the attached agent, the assistant or Claw. */
@@ -0,0 +1,57 @@
1
+ /**
2
+ * The files of a message to a session the chat is attached to (a coding agent on the person's own machine). A text file
3
+ * (a log, code, data, a document in plain text) is passed inline, after the person's words, whole while the budget lasts
4
+ * and cut after that. Any other file (an image, a PDF) goes as a file where the session's machine takes files (the
5
+ * connector saves it there and names its path in the prompt); where it does not, the person is told which ones did not
6
+ * reach the session, and why.
7
+ */
8
+ import type { FetchedFile, FileRefused, InboundFile } from "../ports/surface.js";
9
+ import type { Result } from "../result.js";
10
+ /** The most bytes of files passed inline with one prompt (a session takes a prompt of at most 64 KiB, words included). */
11
+ export declare const INLINE_FILE_BYTES: number;
12
+ /** The most bytes of one prompt to a session: Claw takes at most 64 KiB; the rest is room for what frames it. */
13
+ export declare const SESSION_PROMPT_BYTES: number;
14
+ /** What is said where forwarded or quoted text was cut to fit one prompt. */
15
+ export declare const QUOTE_CUT = "\n\u2026 [cut: the rest of the forwarded and quoted messages did not fit in one message to the session]";
16
+ /** What is said in place of forwarded or quoted text when none of it fits beside the person's words. */
17
+ export declare const QUOTE_DROPPED = "[cut: the forwarded and quoted messages did not fit in one message to the session]";
18
+ /**
19
+ * The forwarded and quoted messages (`quote`) cut so that they and the person's words (`sent`) fit one prompt to a
20
+ * session: the words are the person's and go whole; what others wrote is cut at its end, and says so. When the words
21
+ * leave no room for any of it, the notice alone stands for it (a few bytes past the budget, inside Claw's own limit).
22
+ */
23
+ export declare function fitQuote(quote: string, sent: string): string;
24
+ /** The bytes of files that may follow `words` in one prompt to a session (at most `INLINE_FILE_BYTES`). */
25
+ export declare function roomAfter(words: string): number;
26
+ /** The type a file is judged by: the one the channel gave, else the extension of its name ("" none). */
27
+ export declare function typeOf(file: Pick<InboundFile, "name" | "type">): string;
28
+ /** Whether a file is one passed inline: a text type (an image never is). */
29
+ export declare function passesInline(file: Pick<InboundFile, "name" | "type">): boolean;
30
+ /** The most files, and bytes of them in all, one prompt carries to a machine (the wire contract's limits). */
31
+ export declare const SESSION_FILES = 10;
32
+ export declare const SESSION_FILE_BYTES: number;
33
+ /** What became of a message's files on their way to a session. */
34
+ export interface InlineFiles {
35
+ /** The text that goes after the person's words ("" none). */
36
+ readonly section: string;
37
+ /** How many files it carries inline. */
38
+ readonly passed: number;
39
+ /** The files that go as files (the machine saves them and names them in the prompt): only where it `takesFiles`. */
40
+ readonly files: FetchedFile[];
41
+ /** [name the person knows it by, why it did not reach the session]. */
42
+ readonly notPassed: [name: string, why: string][];
43
+ }
44
+ export interface InlineOptions {
45
+ /** The most bytes of text passed inline. */
46
+ readonly budget?: number;
47
+ /** The session's machine takes files: a file that is not text goes as a file (fetched), not named back. */
48
+ readonly asFiles?: boolean;
49
+ }
50
+ type Fetch = (file: InboundFile) => Promise<Result<FetchedFile, FileRefused>>;
51
+ /**
52
+ * The files, fetched through `fetch` (an image or another file that is not text only when the machine takes files), as
53
+ * the text that follows the person's words to the session and the files that go with it. `shown(file, i)` is the name
54
+ * the person knows file i (1-based) by.
55
+ */
56
+ export declare function inlineFiles(files: readonly InboundFile[], fetch: Fetch, shown: (file: InboundFile, index: number) => string, options?: InlineOptions): Promise<InlineFiles>;
57
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primusclaw/personal-agent",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "description": "The personal agent's channel-neutral core: domain logic, ports and plugin interfaces.",
5
5
  "license": "MIT",
6
6
  "repository": {