cyrus-edge-worker 0.2.72-test.2 → 0.2.72

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,50 @@
1
+ /**
2
+ * Global concurrency cap for agent runner sessions.
3
+ *
4
+ * Every runner created by the EdgeWorker resolves `start()` /
5
+ * `startStreaming()` only when its session finishes, so holding a semaphore
6
+ * slot for the duration of that promise bounds how many sessions execute at
7
+ * once. Hosts running many webhook-driven sessions use this to keep total
8
+ * runner memory/CPU inside what the machine can serve, instead of letting an
9
+ * unbounded burst of sessions take the whole process down (e.g. via the
10
+ * kernel OOM killer).
11
+ */
12
+ import type { IAgentRunner } from "cyrus-core";
13
+ /**
14
+ * Counting semaphore with FIFO waiters and a live-adjustable limit.
15
+ *
16
+ * `Number.POSITIVE_INFINITY` means uncapped — `acquire()` resolves
17
+ * immediately. Lowering the limit never interrupts running sessions; it
18
+ * simply stops admitting new ones until enough slots free up.
19
+ */
20
+ export declare class SessionSemaphore {
21
+ private limit;
22
+ private readonly onQueued?;
23
+ private activeCount;
24
+ private waiters;
25
+ constructor(limit: number, onQueued?: ((message: string) => void) | undefined);
26
+ get active(): number;
27
+ get waiting(): number;
28
+ get currentLimit(): number;
29
+ acquire(): Promise<void>;
30
+ release(): void;
31
+ /**
32
+ * Adjust the limit at runtime (config hot-reload). Raising it admits
33
+ * queued sessions immediately; lowering it applies as sessions finish.
34
+ */
35
+ setLimit(limit: number): void;
36
+ private admitWaiters;
37
+ }
38
+ /**
39
+ * Wrap a runner so `start()` and `startStreaming()` hold a semaphore slot for
40
+ * their full duration. Both resolve when the session completes, so the slot
41
+ * is held for the session's lifetime and released on success and failure
42
+ * alike. Follow-up messages streamed into an already-started session
43
+ * (`addStreamMessage`) are untouched — the session already holds its slot.
44
+ *
45
+ * The wrapper is a Proxy rather than an instance mutation: the underlying
46
+ * runner is never modified, every other property forwards through unchanged,
47
+ * and the original methods stay observable (e.g. as test spies).
48
+ */
49
+ export declare function capRunnerStarts(runner: IAgentRunner, semaphore: SessionSemaphore): IAgentRunner;
50
+ //# sourceMappingURL=RunnerConcurrency.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RunnerConcurrency.d.ts","sourceRoot":"","sources":["../src/RunnerConcurrency.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C;;;;;;GAMG;AACH,qBAAa,gBAAgB;IAK3B,OAAO,CAAC,KAAK;IACb,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC;IAL3B,OAAO,CAAC,WAAW,CAAK;IACxB,OAAO,CAAC,OAAO,CAAyB;gBAG/B,KAAK,EAAE,MAAM,EACJ,QAAQ,CAAC,GAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,aAAA;IAStD,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,IAAI,OAAO,IAAI,MAAM,CAEpB;IAED,IAAI,YAAY,IAAI,MAAM,CAEzB;IAED,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAexB,OAAO,IAAI,IAAI;IAUf;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAU7B,OAAO,CAAC,YAAY;CAOpB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAC9B,MAAM,EAAE,YAAY,EACpB,SAAS,EAAE,gBAAgB,GACzB,YAAY,CA0Bd"}
@@ -0,0 +1,116 @@
1
+ /**
2
+ * Global concurrency cap for agent runner sessions.
3
+ *
4
+ * Every runner created by the EdgeWorker resolves `start()` /
5
+ * `startStreaming()` only when its session finishes, so holding a semaphore
6
+ * slot for the duration of that promise bounds how many sessions execute at
7
+ * once. Hosts running many webhook-driven sessions use this to keep total
8
+ * runner memory/CPU inside what the machine can serve, instead of letting an
9
+ * unbounded burst of sessions take the whole process down (e.g. via the
10
+ * kernel OOM killer).
11
+ */
12
+ /**
13
+ * Counting semaphore with FIFO waiters and a live-adjustable limit.
14
+ *
15
+ * `Number.POSITIVE_INFINITY` means uncapped — `acquire()` resolves
16
+ * immediately. Lowering the limit never interrupts running sessions; it
17
+ * simply stops admitting new ones until enough slots free up.
18
+ */
19
+ export class SessionSemaphore {
20
+ limit;
21
+ onQueued;
22
+ activeCount = 0;
23
+ waiters = [];
24
+ constructor(limit, onQueued) {
25
+ this.limit = limit;
26
+ this.onQueued = onQueued;
27
+ if (Number.isNaN(limit) || limit < 1) {
28
+ throw new Error(`SessionSemaphore limit must be >= 1 or Infinity, got ${limit}`);
29
+ }
30
+ }
31
+ get active() {
32
+ return this.activeCount;
33
+ }
34
+ get waiting() {
35
+ return this.waiters.length;
36
+ }
37
+ get currentLimit() {
38
+ return this.limit;
39
+ }
40
+ acquire() {
41
+ if (this.activeCount < this.limit) {
42
+ this.activeCount++;
43
+ return Promise.resolve();
44
+ }
45
+ return new Promise((resolve) => {
46
+ this.waiters.push(resolve);
47
+ this.onQueued?.(`Session start queued: ${this.activeCount} running at the ` +
48
+ `maxConcurrentSessions limit of ${this.limit}, ` +
49
+ `${this.waiters.length} waiting`);
50
+ });
51
+ }
52
+ release() {
53
+ if (this.activeCount === 0) {
54
+ // A release with nothing active is a bookkeeping bug in the caller;
55
+ // clamp rather than let the count go negative and over-admit later.
56
+ return;
57
+ }
58
+ this.activeCount--;
59
+ this.admitWaiters();
60
+ }
61
+ /**
62
+ * Adjust the limit at runtime (config hot-reload). Raising it admits
63
+ * queued sessions immediately; lowering it applies as sessions finish.
64
+ */
65
+ setLimit(limit) {
66
+ if (Number.isNaN(limit) || limit < 1) {
67
+ throw new Error(`SessionSemaphore limit must be >= 1 or Infinity, got ${limit}`);
68
+ }
69
+ this.limit = limit;
70
+ this.admitWaiters();
71
+ }
72
+ admitWaiters() {
73
+ while (this.waiters.length > 0 && this.activeCount < this.limit) {
74
+ this.activeCount++;
75
+ const next = this.waiters.shift();
76
+ next?.();
77
+ }
78
+ }
79
+ }
80
+ /**
81
+ * Wrap a runner so `start()` and `startStreaming()` hold a semaphore slot for
82
+ * their full duration. Both resolve when the session completes, so the slot
83
+ * is held for the session's lifetime and released on success and failure
84
+ * alike. Follow-up messages streamed into an already-started session
85
+ * (`addStreamMessage`) are untouched — the session already holds its slot.
86
+ *
87
+ * The wrapper is a Proxy rather than an instance mutation: the underlying
88
+ * runner is never modified, every other property forwards through unchanged,
89
+ * and the original methods stay observable (e.g. as test spies).
90
+ */
91
+ export function capRunnerStarts(runner, semaphore) {
92
+ const gate = async (run) => {
93
+ await semaphore.acquire();
94
+ try {
95
+ return await run();
96
+ }
97
+ finally {
98
+ semaphore.release();
99
+ }
100
+ };
101
+ return new Proxy(runner, {
102
+ get(target, property, receiver) {
103
+ if (property === "start") {
104
+ return (prompt) => gate(() => target.start(prompt));
105
+ }
106
+ if (property === "startStreaming" &&
107
+ typeof target.startStreaming === "function") {
108
+ return (initialPrompt) =>
109
+ // biome-ignore lint/style/noNonNullAssertion: guarded by the typeof check above
110
+ gate(() => target.startStreaming(initialPrompt));
111
+ }
112
+ return Reflect.get(target, property, receiver);
113
+ },
114
+ });
115
+ }
116
+ //# sourceMappingURL=RunnerConcurrency.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RunnerConcurrency.js","sourceRoot":"","sources":["../src/RunnerConcurrency.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH;;;;;;GAMG;AACH,MAAM,OAAO,gBAAgB;IAKnB;IACS;IALV,WAAW,GAAG,CAAC,CAAC;IAChB,OAAO,GAAsB,EAAE,CAAC;IAExC,YACS,KAAa,EACJ,QAAoC;QAD7C,UAAK,GAAL,KAAK,CAAQ;QACJ,aAAQ,GAAR,QAAQ,CAA4B;QAErD,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;YACtC,MAAM,IAAI,KAAK,CACd,wDAAwD,KAAK,EAAE,CAC/D,CAAC;QACH,CAAC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ILogger } from "cyrus-core";
2
+ import { ZulipMessageService, type ZulipWebhookEvent } from "cyrus-zulip-event-transport";
3
+ import type { ChatRepositoryProvider } from "./ChatRepositoryProvider.js";
4
+ import type { ChatPlatformAdapter } from "./ChatSessionHandler.js";
5
+ /** Reaction added when a message is received and queued for processing (👀) */
6
+ export declare const RECEIPT_REACTION = "eyes";
7
+ /**
8
+ * Reaction that replaces the receipt one once the agent finished its turn (✅).
9
+ *
10
+ * Zulip's name for U+2705 is `check`, not the `white_check_mark` that Slack
11
+ * and GitHub use — Zulip rejects an unknown name with a 400, and
12
+ * `check_mark` is a different emoji (U+2714 ✔️).
13
+ */
14
+ export declare const PROCESSED_REACTION = "check";
15
+ /**
16
+ * Zulip implementation of ChatPlatformAdapter.
17
+ *
18
+ * A Zulip topic is the thread unit, so a channel message's thread key is
19
+ * `<stream_id>:<topic>`; a DM conversation keys on its participants instead.
20
+ *
21
+ * Unlike Slack, an outgoing webhook bot is only notified about messages that
22
+ * address it (an @mention or a DM), so every event Cyrus sees is directed at
23
+ * it. That removes the whole "decide whether this message was meant for you"
24
+ * apparatus the Slack prompt needs — and it is why the catch-up read matters:
25
+ * it is the only way anything said in the topic between two mentions reaches
26
+ * the agent.
27
+ */
28
+ export declare class ZulipChatAdapter implements ChatPlatformAdapter<ZulipWebhookEvent> {
29
+ readonly platformName: "zulip";
30
+ private repositoryProvider;
31
+ private repositoryRoutingContext;
32
+ private messageService;
33
+ private logger;
34
+ constructor(repositoryProvider: ChatRepositoryProvider, logger?: ILogger, options?: {
35
+ repositoryRoutingContext?: string;
36
+ messageService?: ZulipMessageService;
37
+ });
38
+ extractTaskInstructions(event: ZulipWebhookEvent): string;
39
+ getThreadKey(event: ZulipWebhookEvent): string;
40
+ getEventId(event: ZulipWebhookEvent): string;
41
+ /**
42
+ * Only channel topics get a catch-up cursor. Every DM sent to the bot
43
+ * triggers the webhook, so a DM session has already seen its whole
44
+ * conversation and re-reading it would only duplicate context.
45
+ */
46
+ getThreadContextTs(event: ZulipWebhookEvent): string | undefined;
47
+ /**
48
+ * What was said in this topic since Cyrus last had context.
49
+ *
50
+ * One request either way: the newest window of the topic, from which the
51
+ * cursor selects what the agent has not seen. A resumed session already
52
+ * holds its own replies in memory, so those are dropped from a catch-up —
53
+ * but a fresh session has no memory at all and gets the whole window,
54
+ * Cyrus's own past replies included.
55
+ *
56
+ * Returns "" when there is nothing to add, `null` when the read failed —
57
+ * the caller only advances its cursor on a non-null result, so a failure
58
+ * retries the same window on the next mention instead of losing it.
59
+ */
60
+ fetchThreadContext(event: ZulipWebhookEvent, sinceTs?: string): Promise<string | null>;
61
+ buildSystemPrompt(event: ZulipWebhookEvent): string;
62
+ postReply(event: ZulipWebhookEvent, runner: IAgentRunner): Promise<void>;
63
+ acknowledgeReceipt(event: ZulipWebhookEvent): Promise<void>;
64
+ /**
65
+ * Swap the receipt reaction (👀) for a processed one (✅) once the agent
66
+ * has finished its turn for this message.
67
+ */
68
+ acknowledgeProcessed(event: ZulipWebhookEvent): Promise<void>;
69
+ notifyBusy(event: ZulipWebhookEvent): Promise<void>;
70
+ /** Where a reply to this message should go */
71
+ private destinationFor;
72
+ /** Participants of a DM conversation, sorted so the key is stable */
73
+ private recipientIds;
74
+ /**
75
+ * The topic's name with any resolved marker removed, for identity only.
76
+ *
77
+ * Every call that actually addresses Zulip — posting a reply, narrowing a
78
+ * history read — uses the raw subject instead, because that is the topic's
79
+ * real name right now.
80
+ */
81
+ private unresolvedTopic;
82
+ /** Channel name of a channel message, needed to build a narrow */
83
+ private channelName;
84
+ private parseCursor;
85
+ private formatTopicContext;
86
+ }
87
+ //# sourceMappingURL=ZulipChatAdapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ZulipChatAdapter.d.ts","sourceRoot":"","sources":["../src/ZulipChatAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAExD,OAAO,EAIN,mBAAmB,EACnB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kB,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAQjE;;;OAGG;IACG,oBAAoB,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAe7D,UAAU,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IASzD,8CAA8C;IAC9C,OAAO,CAAC,cAAc;IAWtB,qEAAqE;IACrE,OAAO,CAAC,YAAY;IAUpB;;;;;;OAMG;IACH,OAAO,CAAC,eAAe;IAMvB,kEAAkE;IAClE,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,kBAAkB;CAsB1B"}
@@ -0,0 +1,322 @@
1
+ import { createLogger } from "cyrus-core";
2
+ import { buildPromptText, ZulipMessageService, } from "cyrus-zulip-event-transport";
3
+ /** How many topic messages a single catch-up read carries. */
4
+ const TOPIC_CONTEXT_MESSAGE_LIMIT = 50;
5
+ /** Reaction added when a message is received and queued for processing (👀) */
6
+ export const RECEIPT_REACTION = "eyes";
7
+ /**
8
+ * Reaction that replaces the receipt one once the agent finished its turn (✅).
9
+ *
10
+ * Zulip's name for U+2705 is `check`, not the `white_check_mark` that Slack
11
+ * and GitHub use — Zulip rejects an unknown name with a 400, and
12
+ * `check_mark` is a different emoji (U+2714 ✔️).
13
+ */
14
+ export const PROCESSED_REACTION = "check";
15
+ /**
16
+ * Prefix Zulip puts on a topic's name when someone marks it resolved.
17
+ *
18
+ * Resolving renames the topic rather than setting a flag, so one continuous
19
+ * conversation arrives under two different names over its life. Keying a
20
+ * session on the raw name would strand that session — and its catch-up
21
+ * cursor — the moment anyone resolves or unresolves the topic, which is a
22
+ * routine action rather than an edge case.
23
+ */
24
+ const RESOLVED_TOPIC_PREFIX = "\u2714 ";
25
+ /**
26
+ * Width the message ID cursor is padded to.
27
+ *
28
+ * ChatSessionHandler compares thread cursors as strings (Slack timestamps are
29
+ * zero-padded, so string order is chronological there). Zulip message IDs are
30
+ * plain integers, where `"9" > "10"` — a raw ID would make the cursor move
31
+ * backwards and re-deliver messages. Padding restores chronological string
32
+ * ordering; `parseCursor` undoes it before the ID reaches the API.
33
+ */
34
+ const CURSOR_WIDTH = 20;
35
+ /**
36
+ * Zulip implementation of ChatPlatformAdapter.
37
+ *
38
+ * A Zulip topic is the thread unit, so a channel message's thread key is
39
+ * `<stream_id>:<topic>`; a DM conversation keys on its participants instead.
40
+ *
41
+ * Unlike Slack, an outgoing webhook bot is only notified about messages that
42
+ * address it (an @mention or a DM), so every event Cyrus sees is directed at
43
+ * it. That removes the whole "decide whether this message was meant for you"
44
+ * apparatus the Slack prompt needs — and it is why the catch-up read matters:
45
+ * it is the only way anything said in the topic between two mentions reaches
46
+ * the agent.
47
+ */
48
+ export class ZulipChatAdapter {
49
+ platformName = "zulip";
50
+ repositoryProvider;
51
+ repositoryRoutingContext;
52
+ messageService;
53
+ logger;
54
+ constructor(repositoryProvider, logger, options) {
55
+ this.repositoryProvider = repositoryProvider;
56
+ this.repositoryRoutingContext =
57
+ options?.repositoryRoutingContext?.trim() || "";
58
+ this.messageService = options?.messageService ?? new ZulipMessageService();
59
+ this.logger = logger ?? createLogger({ component: "ZulipChatAdapter" });
60
+ }
61
+ extractTaskInstructions(event) {
62
+ return buildPromptText(event.data) || "Ask the user for more context";
63
+ }
64
+ getThreadKey(event) {
65
+ const { message } = event;
66
+ if (message.type === "stream") {
67
+ return `${message.stream_id}:${this.unresolvedTopic(message.subject)}`;
68
+ }
69
+ return `dm:${this.recipientIds(message).join(",")}`;
70
+ }
71
+ getEventId(event) {
72
+ return String(event.message.id);
73
+ }
74
+ /**
75
+ * Only channel topics get a catch-up cursor. Every DM sent to the bot
76
+ * triggers the webhook, so a DM session has already seen its whole
77
+ * conversation and re-reading it would only duplicate context.
78
+ */
79
+ getThreadContextTs(event) {
80
+ if (event.message.type !== "stream") {
81
+ return undefined;
82
+ }
83
+ return String(event.message.id).padStart(CURSOR_WIDTH, "0");
84
+ }
85
+ /**
86
+ * What was said in this topic since Cyrus last had context.
87
+ *
88
+ * One request either way: the newest window of the topic, from which the
89
+ * cursor selects what the agent has not seen. A resumed session already
90
+ * holds its own replies in memory, so those are dropped from a catch-up —
91
+ * but a fresh session has no memory at all and gets the whole window,
92
+ * Cyrus's own past replies included.
93
+ *
94
+ * Returns "" when there is nothing to add, `null` when the read failed —
95
+ * the caller only advances its cursor on a non-null result, so a failure
96
+ * retries the same window on the next mention instead of losing it.
97
+ */
98
+ async fetchThreadContext(event, sinceTs) {
99
+ const { message } = event;
100
+ if (message.type !== "stream") {
101
+ return "";
102
+ }
103
+ const channel = this.channelName(message);
104
+ if (!channel) {
105
+ this.logger.warn(`Cannot fetch Zulip topic context: no channel name on message ${message.id}`);
106
+ return null;
107
+ }
108
+ const sinceId = sinceTs ? this.parseCursor(sinceTs) : undefined;
109
+ try {
110
+ const messages = await this.messageService.fetchTopicMessages({
111
+ credentials: event.credentials,
112
+ channel,
113
+ topic: message.subject,
114
+ limit: TOPIC_CONTEXT_MESSAGE_LIMIT,
115
+ });
116
+ // Zulip returns the window oldest-first. Filling it means the topic
117
+ // (or the gap since the cursor) is longer than one window and its
118
+ // oldest messages fell off — worth saying so, rather than letting the
119
+ // agent read a partial history as if it were complete.
120
+ const oldestId = messages[0]?.id;
121
+ const omittedEarlier = messages.length >= TOPIC_CONTEXT_MESSAGE_LIMIT &&
122
+ oldestId !== undefined &&
123
+ (sinceId === undefined || oldestId > sinceId);
124
+ const relevant = messages.filter((msg) => {
125
+ // Already carried by the task instructions
126
+ if (msg.id === message.id) {
127
+ return false;
128
+ }
129
+ if (sinceId === undefined) {
130
+ return true;
131
+ }
132
+ // Already seen: either before the cursor, or said by this session
133
+ return msg.id > sinceId && msg.sender_email !== event.botEmail;
134
+ });
135
+ if (relevant.length === 0) {
136
+ return "";
137
+ }
138
+ const preamble = sinceId === undefined
139
+ ? ""
140
+ : "The following messages were posted in this topic since you last had context. Read them for background before responding.\n\n";
141
+ const truncationNote = omittedEarlier
142
+ ? "Older messages in this topic are not shown.\n\n"
143
+ : "";
144
+ return `${preamble}${truncationNote}${this.formatTopicContext(relevant, event.botEmail)}`;
145
+ }
146
+ catch (error) {
147
+ this.logger.warn(`Failed to fetch Zulip topic context: ${error instanceof Error ? error.message : String(error)}`);
148
+ return null;
149
+ }
150
+ }
151
+ buildSystemPrompt(event) {
152
+ const repositoryPaths = Array.from(new Set(this.repositoryProvider.getRepositoryPaths().filter(Boolean))).sort();
153
+ const repositoryAccessSection = repositoryPaths.length > 0
154
+ ? `
155
+ ## Repository Access
156
+ - You have read-only access to the following configured repositories:
157
+ ${repositoryPaths.map((path) => `- ${path}`).join("\n")}
158
+
159
+ - If you need to inspect source code in one of these repositories, use:
160
+ - Bash(git -C * pull)
161
+
162
+ - You are explicitly allowed to run git pull with:
163
+ - Bash(git -C * pull)
164
+ `
165
+ : `
166
+ ## Repository Access
167
+ - No repository paths are configured for this chat session.`;
168
+ const { message } = event;
169
+ const location = message.type === "stream"
170
+ ? `- **Channel**: ${this.channelName(message) ?? message.stream_id}\n- **Topic**: ${message.subject}`
171
+ : "- **Direct message**";
172
+ return `You are participating in a Zulip conversation.
173
+
174
+ ## Context
175
+ - **Requested by**: ${message.sender_full_name} (${message.sender_email})
176
+ ${location}
177
+
178
+ ## When to Respond
179
+ - You are only notified about messages that address you directly — an @mention in a channel, or a direct message. Every message you receive is meant for you, so always respond.
180
+ - You may be given a catch-up block of messages posted since you last replied. That is background for your answer, not a set of requests to answer one by one.
181
+ - Be genuinely helpful and concise.
182
+
183
+ ## Instructions
184
+ - You are running in a transient workspace, not associated with any code repository
185
+ - Be concise in your responses as they will be posted back to Zulip
186
+ - If the user's request involves code changes, help them plan the work and suggest creating an issue in their project tracker (Linear, Jira, or GitHub Issues)
187
+ - You can answer questions, provide analysis, help with planning, and assist with research
188
+ - If files need to be created or examined, they will be in your working directory
189
+ ${repositoryAccessSection}
190
+ ${this.repositoryRoutingContext ? `\n\n${this.repositoryRoutingContext}` : ""}
191
+
192
+ ## Self-Knowledge
193
+ - If the user asks about your capabilities, features, how you work, what you can do, setup instructions, or anything related to Cyrus documentation, use the \`mcp__cyrus-docs__search_documentation\` tool to look up the answer from the official Cyrus docs.
194
+ - Always prefer searching the docs over guessing or relying on your training data for Cyrus-specific questions.
195
+
196
+ ## Orchestration Notes
197
+ - If the user asks you to make repo code changes immediately, use these steps:
198
+ - First run \`mcp__linear__get_user\` with \`query: "me"\` to get your Linear identity.
199
+ - Create an Issue in the user's tracker for the requested work (for example using \`mcp__linear__save_issue\`), including enough context and acceptance criteria to execute it. Default the issue status/state to "Backlog". **IMPORTANT: Never set the status to "Triage".**
200
+ - To route the issue to a specific repository, add \`[repo=repo-name]\` to the issue description. To target a specific branch, use \`[repo=repo-name#branch-name]\`. For multiple repos: \`repos=repo1,repo2\`.
201
+ - To choose a specific execution harness, add \`[agent=claude]\`, \`[agent=gemini]\`, \`[agent=codex]\`, \`[agent=cursor]\`, or \`[agent=opencode]\` to the issue description.
202
+ - To choose both execution harness and model from Linear labels, apply a \`<provider>/<model>\` label such as \`openai/gpt-5.5\`. For OpenCode, use \`opencode/<provider>/<model>\`, such as \`opencode/openai/gpt-5.5\`.
203
+ - Assign that Issue to that same user (your own Linear user).
204
+ - That assignment is what immediately kicks off work in your own agent session.
205
+ - Track execution progress by searching \`mcp__cyrus-tools__linear_get_agent_sessions\` for the active session, then opening it with \`mcp__cyrus-tools__linear_get_agent_session\`.
206
+ - To send mid-flight feedback or corrections to a running child session, use \`mcp__cyrus-tools__linear_agent_give_feedback\` with the session ID returned by \`linear_get_agent_sessions\`. This is the ONLY way to directly prompt a running child agent. \`mcp__linear__save_comment\` does NOT trigger or notify the agent in any way — it just writes a comment on the issue, which the running session will not see. Always prefer \`linear_agent_give_feedback\` when the child agent is actively working.
207
+
208
+ ## Zulip Message Formatting
209
+ Your response is posted as a Zulip message. Zulip uses Markdown, so ordinary Markdown is correct — including \`[text](url)\` links, \`**bold**\`, tables, and fenced code blocks (give them a language, e.g. \`\`\`python).
210
+
211
+ Two Zulip-specific rules:
212
+ - To mention someone, write \`@**Full Name**\`. A plain \`@name\` does not notify anyone.
213
+ - Do not use headers (\`#\`). Zulip messages are short; use \`**bold**\` on its own line to separate sections.`;
214
+ }
215
+ async postReply(event, runner) {
216
+ try {
217
+ const messages = runner.getMessages();
218
+ const lastAssistantMessage = [...messages]
219
+ .reverse()
220
+ .find((m) => m.type === "assistant");
221
+ let summary = "Task completed.";
222
+ if (lastAssistantMessage &&
223
+ lastAssistantMessage.type === "assistant" &&
224
+ "message" in lastAssistantMessage) {
225
+ const msg = lastAssistantMessage;
226
+ const textBlock = msg.message.content?.find((block) => block.type === "text" && block.text);
227
+ if (textBlock?.text) {
228
+ summary = textBlock.text;
229
+ }
230
+ }
231
+ await this.messageService.postMessage({
232
+ credentials: event.credentials,
233
+ destination: this.destinationFor(event.message),
234
+ content: summary,
235
+ });
236
+ this.logger.info(`Posted Zulip reply (thread ${this.getThreadKey(event)})`);
237
+ }
238
+ catch (error) {
239
+ this.logger.error("Failed to post Zulip reply", error instanceof Error ? error : new Error(String(error)));
240
+ }
241
+ }
242
+ async acknowledgeReceipt(event) {
243
+ await this.messageService.addReaction(event.credentials, event.message.id, RECEIPT_REACTION);
244
+ }
245
+ /**
246
+ * Swap the receipt reaction (👀) for a processed one (✅) once the agent
247
+ * has finished its turn for this message.
248
+ */
249
+ async acknowledgeProcessed(event) {
250
+ // Remove before adding so the two are never visible together — the swap
251
+ // reads as a clean transition.
252
+ await this.messageService.removeReaction(event.credentials, event.message.id, RECEIPT_REACTION);
253
+ await this.messageService.addReaction(event.credentials, event.message.id, PROCESSED_REACTION);
254
+ }
255
+ async notifyBusy(event) {
256
+ await this.messageService.postMessage({
257
+ credentials: event.credentials,
258
+ destination: this.destinationFor(event.message),
259
+ content: "I'm still working on the previous request in this topic. I'll pick up your new message once I'm done.",
260
+ });
261
+ }
262
+ /** Where a reply to this message should go */
263
+ destinationFor(message) {
264
+ if (message.type === "stream" && message.stream_id !== undefined) {
265
+ return {
266
+ type: "stream",
267
+ streamId: message.stream_id,
268
+ topic: message.subject,
269
+ };
270
+ }
271
+ return { type: "private", userIds: this.recipientIds(message) };
272
+ }
273
+ /** Participants of a DM conversation, sorted so the key is stable */
274
+ recipientIds(message) {
275
+ const recipients = Array.isArray(message.display_recipient)
276
+ ? message.display_recipient
277
+ : [];
278
+ if (recipients.length === 0) {
279
+ return [message.sender_id];
280
+ }
281
+ return recipients.map((recipient) => recipient.id).sort((a, b) => a - b);
282
+ }
283
+ /**
284
+ * The topic's name with any resolved marker removed, for identity only.
285
+ *
286
+ * Every call that actually addresses Zulip — posting a reply, narrowing a
287
+ * history read — uses the raw subject instead, because that is the topic's
288
+ * real name right now.
289
+ */
290
+ unresolvedTopic(subject) {
291
+ return subject.startsWith(RESOLVED_TOPIC_PREFIX)
292
+ ? subject.slice(RESOLVED_TOPIC_PREFIX.length)
293
+ : subject;
294
+ }
295
+ /** Channel name of a channel message, needed to build a narrow */
296
+ channelName(message) {
297
+ return typeof message.display_recipient === "string"
298
+ ? message.display_recipient
299
+ : undefined;
300
+ }
301
+ parseCursor(cursor) {
302
+ return Number(cursor);
303
+ }
304
+ formatTopicContext(messages, botEmail) {
305
+ const formattedMessages = messages
306
+ .map((msg) => {
307
+ const author = msg.sender_email === botEmail
308
+ ? "assistant (you)"
309
+ : msg.sender_full_name;
310
+ return ` <message>
311
+ <author>${author}</author>
312
+ <id>${msg.id}</id>
313
+ <content>
314
+ ${msg.content}
315
+ </content>
316
+ </message>`;
317
+ })
318
+ .join("\n");
319
+ return `<zulip_topic_context>\n${formattedMessages}\n</zulip_topic_context>`;
320
+ }
321
+ }
322
+ //# sourceMappingURL=ZulipChatAdapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ZulipChatAdapter.js","sourceRoot":"","sources":["../src/ZulipChatAdapter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,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IAC9E,CAAC;CACD"}
package/dist/index.d.ts CHANGED
@@ -30,4 +30,5 @@ export { ToolPermissionResolver } from "./ToolPermissionResolver.js";
30
30
  export type { EdgeWorkerEvents } from "./types.js";
31
31
  export { type AccessCheckResult, DEFAULT_BLOCK_MESSAGE, UserAccessControl, } from "./UserAccessControl.js";
32
32
  export { WorktreeIncludeService } from "./WorktreeIncludeService.js";
33
+ export { ZulipChatAdapter } from "./ZulipChatAdapter.js";
33
34
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,YAAY,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACjE,YAAY,EACX,UAAU,EACV,gBAAgB,EAChB,oBAAoB,EACpB,gBAAgB,EAChB,uBAAuB,EACvB,cAAc,EACd,SAAS,GACT,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,YAAY,EACX,4BAA4B,EAC5B,0BAA0B,GAC1B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,YAAY,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAC1E,OAAO,EAAE,0BAA0B,EAAE,MAAM,6BAA6B,CAAC;AACzE,YAAY,EACX,mBAAmB,EACnB,gBAAgB,EAChB,sBAAsB,GACtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,YAAY,EAAE,wBAAwB,E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,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,YAAY,EACX,mBAAmB,EACnB,kBAAkB,EAClB,cAAc,EACd,aAAa,GACb,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,YAAY,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,YAAY,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD,OAAO,EACN,KAAK,iBAAiB,EACtB,qBAAqB,EACrB,iBAAiB,GACjB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC"}
package/dist/index.js CHANGED
@@ -19,4 +19,5 @@ export { ToolPermissionResolver } from "./ToolPermissionResolver.js";
19
19
  // User access control
20
20
  export { DEFAULT_BLOCK_MESSAGE, UserAccessControl, } from "./UserAccessControl.js";
21
21
  export { WorktreeIncludeService } from "./WorktreeIncludeService.js";
22
+ export { ZulipChatAdapter } from "./ZulipChatAdapter.js";
22
23
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAUjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAK/D,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAErE,OAAO,EAAE,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