omp-superagent 0.1.9 → 0.1.11
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/DESIGN.md +68 -21
- package/README.ko.md +30 -372
- package/README.md +31 -419
- package/THIRD_PARTY_NOTICES.md +35 -436
- package/assets/architecture-dark.svg +7 -12
- package/assets/architecture.ko-dark.svg +7 -12
- package/assets/architecture.ko.svg +7 -12
- package/assets/architecture.mmd +5 -13
- package/assets/architecture.svg +7 -12
- package/config.example.json +8 -0
- package/docs/OPERATIONS.en.md +2277 -0
- package/docs/OPERATIONS.md +198 -45
- package/docs/design/execution.md +163 -54
- package/docs/design/messaging.md +125 -34
- package/docs/kakao-bridge-protocol.md +193 -0
- package/docs/releases/0.1.10.md +17 -0
- package/docs/releases/0.1.11.md +18 -0
- package/gateway/bin/omp-gateway-darwin-arm64 +0 -0
- package/gateway/bin/omp-gateway-darwin-x64 +0 -0
- package/gateway/bin/omp-gateway-linux-arm64 +0 -0
- package/gateway/bin/omp-gateway-linux-x64 +0 -0
- package/host-owner/bin/omp-host-owner-darwin-arm64 +0 -0
- package/host-owner/bin/omp-host-owner-darwin-x64 +0 -0
- package/host-owner/bin/omp-host-owner-linux-arm64 +0 -0
- package/host-owner/bin/omp-host-owner-linux-x64 +0 -0
- package/package.json +10 -11
- package/scripts/{prepare-ulw.ts → prepare-super.ts} +1 -1
- package/skills/head/SKILL.md +36 -5
- package/skills/head/references/routing.md +1 -1
- package/skills/head/references/supervision.md +32 -26
- package/skills/lane/SKILL.md +39 -21
- package/skills/lane/references/workflow.md +23 -16
- package/src/cli.ts +35 -33
- package/src/{config.ts → config/config.ts} +51 -6
- package/src/config/wake-config.ts +36 -0
- package/src/contracts.ts +91 -13
- package/src/{cron-jobs.ts → cron/cron-jobs.ts} +21 -13
- package/src/{cron-pr-intake.ts → cron/cron-pr-intake.ts} +4 -4
- package/src/{cron-schedule.ts → cron/cron-schedule.ts} +3 -3
- package/src/extension.ts +64 -28
- package/src/{gateway-client.ts → gateway/gateway-client.ts} +89 -32
- package/src/{gateway-native.ts → gateway/gateway-native.ts} +4 -4
- package/src/{gateway-protocol.ts → gateway/gateway-protocol.ts} +69 -14
- package/src/{gateway-wire.ts → gateway/gateway-wire.ts} +12 -7
- package/src/gateway-config.ts +1 -1
- package/src/gateway-restart-env.ts +3 -3
- package/src/{group-access.ts → group/group-access.ts} +8 -3
- package/src/{group-policy.ts → group/group-policy.ts} +2 -2
- package/src/{group-runner.ts → group/group-runner.ts} +11 -6
- package/src/host-extension.ts +213 -43
- package/src/host-sdk-helper.ts +62 -65
- package/src/{decision-tool.ts → lane/decision-tool.ts} +12 -4
- package/src/{decisions.ts → lane/decisions.ts} +12 -10
- package/src/{lane-models.ts → lane/lane-models.ts} +1 -1
- package/src/{lane-report.ts → lane/lane-report.ts} +22 -0
- package/src/{lane-rows.ts → lane/lane-rows.ts} +2 -2
- package/src/{lane-watch.ts → lane/lane-watch.ts} +6 -2
- package/src/{workflow.ts → lane/workflow.ts} +1 -1
- package/src/lane-extension.ts +69 -13
- package/src/managed-memory-helper.ts +2 -2
- package/src/{managed-ulw-probe.ts → managed-super-probe.ts} +3 -3
- package/src/{delivery.ts → messaging/delivery.ts} +1 -1
- package/src/{discord-command-registration.ts → messaging/discord-command-registration.ts} +3 -2
- package/src/{discord-context.ts → messaging/discord-context.ts} +1 -1
- package/src/{messenger-command-catalog.json → messaging/messenger-command-catalog.json} +1 -0
- package/src/messaging/messenger-commands.ts +55 -0
- package/src/{result-attachment.ts → messaging/result-attachment.ts} +3 -3
- package/src/{slack-command-registration.ts → messaging/slack-command-registration.ts} +3 -3
- package/src/{telegram-command-registration.ts → messaging/telegram-command-registration.ts} +2 -2
- package/src/omp/head-resume.ts +123 -0
- package/src/{host-owner-path.ts → omp/host-owner-path.ts} +1 -1
- package/src/{host-protocol.ts → omp/host-protocol.ts} +11 -2
- package/src/omp/host-reply-voice.ts +181 -0
- package/src/{host-superkit.ts → omp/host-superkit.ts} +1 -1
- package/src/{host.ts → omp/host.ts} +26 -17
- package/src/{installed-omp.ts → omp/installed-omp.ts} +1 -1
- package/src/{managed-memory.ts → omp/managed-memory.ts} +2 -2
- package/src/{managed-ulw.ts → omp/managed-super.ts} +42 -16
- package/src/omp/native-journal.ts +124 -0
- package/src/{native-launch-profile.ts → omp/native-launch-profile.ts} +6 -2
- package/src/{native-presets.ts → omp/native-presets.ts} +2 -2
- package/src/omp/native-sessions.ts +124 -0
- package/src/{omp-usage.ts → omp/omp-usage.ts} +1 -1
- package/src/omp/soul.ts +214 -0
- package/src/omp/stock-head-launch.ts +31 -0
- package/src/{autostart.ts → operator/autostart.ts} +3 -3
- package/src/{operator.ts → operator/operator.ts} +2 -2
- package/src/{setup-judge.ts → operator/setup-judge.ts} +1 -1
- package/src/{setup-profiles.ts → operator/setup-profiles.ts} +2 -2
- package/src/{setup.ts → operator/setup.ts} +7 -6
- package/src/{pr-intake-automation.ts → pr/pr-intake-automation.ts} +1 -1
- package/src/{pr-intake-mode.ts → pr/pr-intake-mode.ts} +3 -3
- package/src/{pr-intake-review.ts → pr/pr-intake-review.ts} +5 -5
- package/src/{pr-intake-work.ts → pr/pr-intake-work.ts} +1 -1
- package/src/{pr-review-models.ts → pr/pr-review-models.ts} +2 -2
- package/src/{pr-watch.ts → pr/pr-watch.ts} +36 -26
- package/src/{message-order.ts → routing/message-order.ts} +3 -2
- package/src/{topic-history.ts → routing/topic-history.ts} +2 -2
- package/src/{topic-request.ts → routing/topic-request.ts} +4 -2
- package/src/{runtime.ts → runtime/controller.ts} +1278 -1267
- package/src/runtime/deferred-routing.ts +106 -0
- package/src/runtime/dm-timeline.ts +194 -0
- package/src/{head-recovery.ts → runtime/head-recovery.ts} +1 -1
- package/src/{head-rotation.ts → runtime/head-rotation.ts} +32 -5
- package/src/runtime/model-journal.ts +119 -0
- package/src/runtime/native-frames.ts +131 -0
- package/src/{observation-request.ts → runtime/observation-request.ts} +1 -1
- package/src/runtime/preset-sync.ts +232 -0
- package/src/runtime/preset-watch-paths.ts +137 -0
- package/src/runtime/result-attachments.ts +146 -0
- package/src/storage/deferred-routing.ts +149 -0
- package/src/{store.ts → storage/store.ts} +450 -49
- package/src/{worker-bridge.ts → worker/worker-bridge.ts} +2 -2
- package/src/{worker-enrollment.ts → worker/worker-enrollment.ts} +2 -2
- package/src/{worker-host.ts → worker/worker-host.ts} +7 -3
- package/src/{worker-placement.ts → worker/worker-placement.ts} +1 -1
- package/src/{worker-profile.ts → worker/worker-profile.ts} +1 -1
- package/src/{worker-registration.ts → worker/worker-registration.ts} +2 -2
- package/src/{worker-request.ts → worker/worker-request.ts} +5 -5
- package/src/{worker-service.ts → worker/worker-service.ts} +2 -2
- package/src/{worker-trust.ts → worker/worker-trust.ts} +1 -1
- package/src/{worker-wire.ts → worker/worker-wire.ts} +3 -3
- package/src/worker-serve-prepare.ts +4 -4
- package/src/board-extension.ts +0 -217
- package/src/board.ts +0 -467
- package/src/gateway-host-helper.ts +0 -13
- package/src/messenger-commands.ts +0 -15
- package/src/native-sessions.ts +0 -34
- /package/src/{credentials.ts → config/credentials.ts} +0 -0
- /package/src/{dialog.ts → messaging/dialog.ts} +0 -0
- /package/src/{telegram-command-languages.json → messaging/telegram-command-languages.json} +0 -0
- /package/src/{host-broker-services.ts → omp/host-broker-services.ts} +0 -0
- /package/src/{host-inventory-manifest.ts → omp/host-inventory-manifest.ts} +0 -0
- /package/src/{host-services.ts → omp/host-services.ts} +0 -0
- /package/src/{native-settings.ts → omp/native-settings.ts} +0 -0
- /package/src/{superkit-skills.ts → omp/superkit-skills.ts} +0 -0
- /package/src/{repository.ts → operator/repository.ts} +0 -0
- /package/src/{pr-github-schema.ts → pr/pr-github-schema.ts} +0 -0
- /package/src/{pr-github.ts → pr/pr-github.ts} +0 -0
- /package/src/{pr-intake-comment.ts → pr/pr-intake-comment.ts} +0 -0
- /package/src/{pr-intake-fix.ts → pr/pr-intake-fix.ts} +0 -0
- /package/src/{pr-intake-github.ts → pr/pr-intake-github.ts} +0 -0
- /package/src/{pr-intake-material.ts → pr/pr-intake-material.ts} +0 -0
- /package/src/{pr-intake-tree.ts → pr/pr-intake-tree.ts} +0 -0
- /package/src/{head-quota.ts → runtime/head-quota.ts} +0 -0
- /package/src/{worker-checkout.ts → worker/worker-checkout.ts} +0 -0
- /package/src/{worker-destination.ts → worker/worker-destination.ts} +0 -0
- /package/src/{worker-doctor.ts → worker/worker-doctor.ts} +0 -0
- /package/src/{worker-ledger.ts → worker/worker-ledger.ts} +0 -0
- /package/src/{worker-repository.ts → worker/worker-repository.ts} +0 -0
- /package/upstream/{ulw.json → super.json} +0 -0
package/src/board.ts
DELETED
|
@@ -1,467 +0,0 @@
|
|
|
1
|
-
import { Database } from "bun:sqlite";
|
|
2
|
-
import { existsSync, realpathSync } from "node:fs";
|
|
3
|
-
import { basename, dirname, isAbsolute, join, resolve } from "node:path";
|
|
4
|
-
import type { Lane } from "./contracts";
|
|
5
|
-
import { HEAD_SESSION_FILE_KEY, activeHeadSessionFile } from "./head-rotation";
|
|
6
|
-
|
|
7
|
-
export interface BoardIdentity {
|
|
8
|
-
role: "head" | "lane";
|
|
9
|
-
actor: string;
|
|
10
|
-
sessionId: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface BoardMessage extends BoardIdentity {
|
|
14
|
-
id: number;
|
|
15
|
-
channel: string;
|
|
16
|
-
thread: number;
|
|
17
|
-
replyTo: number | null;
|
|
18
|
-
text: string;
|
|
19
|
-
mentions: string[];
|
|
20
|
-
createdAt: number;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface BoardPost {
|
|
24
|
-
text: string;
|
|
25
|
-
channel?: string;
|
|
26
|
-
replyTo?: number;
|
|
27
|
-
mentions?: string[];
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface BoardRead {
|
|
31
|
-
channel?: string;
|
|
32
|
-
thread?: number;
|
|
33
|
-
after?: number;
|
|
34
|
-
limit?: number;
|
|
35
|
-
unreadOnly?: boolean;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export type BoardNotice = Omit<BoardMessage, "text">;
|
|
39
|
-
|
|
40
|
-
export interface BoardState {
|
|
41
|
-
identity: BoardIdentity;
|
|
42
|
-
/** Contiguous prefix of bodies actually returned to this session. */
|
|
43
|
-
readCursor: number;
|
|
44
|
-
/** Highest delivered header only; sparse receipts, not this cursor, select notices. */
|
|
45
|
-
noticeCursor: number;
|
|
46
|
-
subscriptions: string[];
|
|
47
|
-
channels: string[];
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export class BoardMembershipError extends Error {
|
|
51
|
-
constructor() { super("This native session is not currently connected to this superagent's shared board"); }
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function canonicalSessionFile(path: string): string {
|
|
55
|
-
try {
|
|
56
|
-
return existsSync(path) ? realpathSync(path) : join(realpathSync(dirname(path)), basename(path));
|
|
57
|
-
} catch {
|
|
58
|
-
throw new BoardMembershipError();
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const SCHEMA = `
|
|
63
|
-
CREATE TABLE IF NOT EXISTS board_sessions (
|
|
64
|
-
session_id TEXT PRIMARY KEY, actor TEXT NOT NULL, role TEXT NOT NULL,
|
|
65
|
-
read_cursor INTEGER NOT NULL DEFAULT 0, notice_cursor INTEGER NOT NULL DEFAULT 0
|
|
66
|
-
);
|
|
67
|
-
CREATE TABLE IF NOT EXISTS board_messages (
|
|
68
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
69
|
-
session_id TEXT NOT NULL REFERENCES board_sessions(session_id),
|
|
70
|
-
actor TEXT NOT NULL, role TEXT NOT NULL, tool_call_id TEXT NOT NULL,
|
|
71
|
-
channel TEXT NOT NULL, thread INTEGER NOT NULL,
|
|
72
|
-
reply_to INTEGER REFERENCES board_messages(id), text TEXT NOT NULL,
|
|
73
|
-
mentions TEXT NOT NULL, created_at INTEGER NOT NULL,
|
|
74
|
-
UNIQUE(session_id, tool_call_id)
|
|
75
|
-
);
|
|
76
|
-
CREATE INDEX IF NOT EXISTS board_channel_order ON board_messages(channel, id);
|
|
77
|
-
CREATE INDEX IF NOT EXISTS board_thread_order ON board_messages(thread, id);
|
|
78
|
-
CREATE INDEX IF NOT EXISTS board_lane_notice_order ON board_messages(id) WHERE role = 'lane';
|
|
79
|
-
CREATE TABLE IF NOT EXISTS board_mentions (
|
|
80
|
-
message_id INTEGER NOT NULL REFERENCES board_messages(id), actor TEXT NOT NULL,
|
|
81
|
-
PRIMARY KEY(message_id, actor)
|
|
82
|
-
);
|
|
83
|
-
CREATE TABLE IF NOT EXISTS board_subscriptions (
|
|
84
|
-
session_id TEXT NOT NULL REFERENCES board_sessions(session_id), channel TEXT NOT NULL,
|
|
85
|
-
PRIMARY KEY(session_id, channel)
|
|
86
|
-
);
|
|
87
|
-
CREATE TABLE IF NOT EXISTS board_receipts (
|
|
88
|
-
session_id TEXT NOT NULL REFERENCES board_sessions(session_id),
|
|
89
|
-
message_id INTEGER NOT NULL REFERENCES board_messages(id),
|
|
90
|
-
read_at INTEGER, noticed_at INTEGER,
|
|
91
|
-
PRIMARY KEY(session_id, message_id)
|
|
92
|
-
);
|
|
93
|
-
CREATE TABLE IF NOT EXISTS board_notice_scans (
|
|
94
|
-
session_id TEXT PRIMARY KEY REFERENCES board_sessions(session_id), position INTEGER NOT NULL
|
|
95
|
-
);
|
|
96
|
-
`;
|
|
97
|
-
|
|
98
|
-
interface NoticeRow {
|
|
99
|
-
id: number;
|
|
100
|
-
session_id: string;
|
|
101
|
-
actor: string;
|
|
102
|
-
role: BoardIdentity["role"];
|
|
103
|
-
channel: string;
|
|
104
|
-
thread: number;
|
|
105
|
-
reply_to: number | null;
|
|
106
|
-
mentions: string;
|
|
107
|
-
created_at: number;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
interface MessageRow extends NoticeRow { text: string }
|
|
111
|
-
|
|
112
|
-
const notice = (row: NoticeRow): BoardNotice => ({
|
|
113
|
-
id: row.id, sessionId: row.session_id, actor: row.actor, role: row.role,
|
|
114
|
-
channel: row.channel, thread: row.thread, replyTo: row.reply_to,
|
|
115
|
-
mentions: JSON.parse(row.mentions) as string[], createdAt: row.created_at,
|
|
116
|
-
});
|
|
117
|
-
const message = (row: MessageRow): BoardMessage => ({ ...notice(row), text: row.text });
|
|
118
|
-
|
|
119
|
-
const UNREAD = `NOT EXISTS (SELECT 1 FROM board_receipts r
|
|
120
|
-
WHERE r.session_id = ? AND r.message_id = m.id AND r.read_at IS NOT NULL)`;
|
|
121
|
-
const UNNOTIFIED = `NOT EXISTS (SELECT 1 FROM board_receipts r
|
|
122
|
-
WHERE r.session_id = ? AND r.message_id = m.id AND (r.read_at IS NOT NULL OR r.noticed_at IS NOT NULL))`;
|
|
123
|
-
|
|
124
|
-
function actorName(value: string): void {
|
|
125
|
-
if (typeof value !== "string" || !/^[a-zA-Z0-9_-]{1,128}$/.test(value)) throw new Error("Invalid board actor");
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function channelName(value: string): void {
|
|
129
|
-
if (value === "general") return;
|
|
130
|
-
if (typeof value !== "string" || !value.startsWith("repo:") || value.length > 4096 ||
|
|
131
|
-
value.includes("\0") || !isAbsolute(value.slice(5)) || resolve(value.slice(5)) !== value.slice(5)) {
|
|
132
|
-
throw new Error("Board channel must be general or repo:<canonical absolute repository path>");
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
function position(value: number, name: string, minimum = 1): void {
|
|
137
|
-
if (!Number.isSafeInteger(value) || value < minimum) throw new Error(`Invalid board ${name}`);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
function pageSize(value = 50): number {
|
|
141
|
-
position(value, "limit");
|
|
142
|
-
if (value > 100) throw new Error("Board limit must be at most 100");
|
|
143
|
-
return value;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/** The caller resolves the Git root first; channel names never execute Git or message content. */
|
|
147
|
-
export function boardRepositoryChannel(repository: string): string {
|
|
148
|
-
const channel = `repo:${realpathSync(repository)}`;
|
|
149
|
-
channelName(channel);
|
|
150
|
-
return channel;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Independent multi-writer connection to the local coordination ledger. Identity
|
|
155
|
-
* comes from the native host/session, never from tool parameters or message text.
|
|
156
|
-
*/
|
|
157
|
-
export class Board {
|
|
158
|
-
private readonly db: Database;
|
|
159
|
-
private readonly identity: Readonly<BoardIdentity>;
|
|
160
|
-
private readonly stateDirectory: string;
|
|
161
|
-
private readonly sessionFile: string;
|
|
162
|
-
private readonly generation: number;
|
|
163
|
-
private closed = false;
|
|
164
|
-
|
|
165
|
-
constructor(path: string, identity: BoardIdentity, readonly repositoryChannel: string, sessionFile: string) {
|
|
166
|
-
actorName(identity.actor);
|
|
167
|
-
if ((identity.role !== "head" && identity.role !== "lane") ||
|
|
168
|
-
(identity.role === "head") !== (identity.actor === "head")) throw new Error("Invalid board role identity");
|
|
169
|
-
if (typeof identity.sessionId !== "string" || !identity.sessionId || identity.sessionId.length > 1024) {
|
|
170
|
-
throw new Error("A native session ID is required for the board");
|
|
171
|
-
}
|
|
172
|
-
channelName(repositoryChannel);
|
|
173
|
-
if (!repositoryChannel.startsWith("repo:")) throw new Error("A repository board channel is required");
|
|
174
|
-
this.identity = Object.freeze({ role: identity.role, actor: identity.actor, sessionId: identity.sessionId });
|
|
175
|
-
// Never register membership or create an instance on tool access. Only the
|
|
176
|
-
// existing runtime's authoritative host/lane records can admit a session.
|
|
177
|
-
if (!existsSync(path) || typeof sessionFile !== "string" || !isAbsolute(sessionFile)) throw new BoardMembershipError();
|
|
178
|
-
path = realpathSync(path);
|
|
179
|
-
this.stateDirectory = dirname(path);
|
|
180
|
-
this.sessionFile = canonicalSessionFile(sessionFile);
|
|
181
|
-
const db = new Database(path, { create: false, strict: true });
|
|
182
|
-
try {
|
|
183
|
-
this.db = db;
|
|
184
|
-
db.run("PRAGMA busy_timeout = 5000");
|
|
185
|
-
this.generation = this.requireMembership();
|
|
186
|
-
db.run("PRAGMA journal_mode = WAL");
|
|
187
|
-
db.run("PRAGMA synchronous = FULL");
|
|
188
|
-
db.run("PRAGMA foreign_keys = ON");
|
|
189
|
-
db.run(SCHEMA);
|
|
190
|
-
db.transaction(() => {
|
|
191
|
-
this.requireMembership();
|
|
192
|
-
const existing = db.query("SELECT actor, role FROM board_sessions WHERE session_id = ?")
|
|
193
|
-
.get(this.identity.sessionId) as { actor: string; role: string } | null;
|
|
194
|
-
if (existing) {
|
|
195
|
-
if (existing.actor !== this.identity.actor || existing.role !== this.identity.role) {
|
|
196
|
-
throw new Error("Native board session identity conflict");
|
|
197
|
-
}
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
|
-
db.query("INSERT INTO board_sessions(session_id, actor, role) VALUES (?, ?, ?)")
|
|
201
|
-
.run(this.identity.sessionId, this.identity.actor, this.identity.role);
|
|
202
|
-
for (const channel of ["general", repositoryChannel]) {
|
|
203
|
-
db.query("INSERT INTO board_subscriptions(session_id, channel) VALUES (?, ?)")
|
|
204
|
-
.run(this.identity.sessionId, channel);
|
|
205
|
-
}
|
|
206
|
-
}).immediate();
|
|
207
|
-
} catch (error) {
|
|
208
|
-
db.close(true);
|
|
209
|
-
throw error;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
post(toolCallId: string, input: BoardPost): BoardMessage {
|
|
214
|
-
if (typeof toolCallId !== "string" || !toolCallId || toolCallId.length > 1024) throw new Error("A native tool call ID is required");
|
|
215
|
-
if (typeof input.text !== "string" || !input.text.trim() || input.text.length > 16000) {
|
|
216
|
-
throw new Error("Board text must contain 1..16000 characters");
|
|
217
|
-
}
|
|
218
|
-
if (input.replyTo !== undefined) position(input.replyTo, "reply parent");
|
|
219
|
-
if (input.mentions !== undefined && (!Array.isArray(input.mentions) || input.mentions.length > 32)) {
|
|
220
|
-
throw new Error("Board mentions must be an array of at most 32 actor IDs");
|
|
221
|
-
}
|
|
222
|
-
const mentions = [...new Set(input.mentions ?? [])].sort();
|
|
223
|
-
for (const actor of mentions) actorName(actor);
|
|
224
|
-
return this.db.transaction(() => {
|
|
225
|
-
this.requireMembership();
|
|
226
|
-
const parent = input.replyTo === undefined ? null : this.get(input.replyTo);
|
|
227
|
-
if (input.replyTo !== undefined && !parent) throw new Error("Board reply parent does not exist");
|
|
228
|
-
const channel = input.channel ?? parent?.channel ?? this.repositoryChannel;
|
|
229
|
-
channelName(channel);
|
|
230
|
-
if (parent && parent.channel !== channel) throw new Error("A board reply must stay in its parent's channel");
|
|
231
|
-
const existing = this.db.query("SELECT * FROM board_messages WHERE session_id = ? AND tool_call_id = ?")
|
|
232
|
-
.get(this.identity.sessionId, toolCallId) as MessageRow | null;
|
|
233
|
-
if (existing) {
|
|
234
|
-
if (existing.channel !== channel || existing.reply_to !== (input.replyTo ?? null) ||
|
|
235
|
-
existing.text !== input.text || existing.mentions !== JSON.stringify(mentions)) {
|
|
236
|
-
throw new Error("Board tool call identity conflict");
|
|
237
|
-
}
|
|
238
|
-
return message(existing);
|
|
239
|
-
}
|
|
240
|
-
const inserted = this.db.query(`INSERT INTO board_messages
|
|
241
|
-
(session_id, actor, role, tool_call_id, channel, thread, reply_to, text, mentions, created_at)
|
|
242
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id`)
|
|
243
|
-
.get(this.identity.sessionId, this.identity.actor, this.identity.role, toolCallId, channel,
|
|
244
|
-
parent?.thread ?? 0, parent?.id ?? null, input.text, JSON.stringify(mentions), Date.now()) as { id: number };
|
|
245
|
-
if (!parent) this.db.query("UPDATE board_messages SET thread = id WHERE id = ?").run(inserted.id);
|
|
246
|
-
for (const actor of mentions) {
|
|
247
|
-
this.db.query("INSERT INTO board_mentions(message_id, actor) VALUES (?, ?)").run(inserted.id, actor);
|
|
248
|
-
}
|
|
249
|
-
// The author receives this exact post as its tool result, not its parent or skipped messages.
|
|
250
|
-
this.markRead([inserted.id]);
|
|
251
|
-
return this.get(inserted.id)!;
|
|
252
|
-
}).immediate();
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
read(input: BoardRead = {}): BoardMessage[] {
|
|
256
|
-
const limit = pageSize(input.limit);
|
|
257
|
-
if (input.channel !== undefined) channelName(input.channel);
|
|
258
|
-
if (input.thread !== undefined) position(input.thread, "thread");
|
|
259
|
-
if (input.after !== undefined) position(input.after, "after position", 0);
|
|
260
|
-
return this.db.transaction(() => {
|
|
261
|
-
this.requireMembership();
|
|
262
|
-
const unread = input.unreadOnly !== false;
|
|
263
|
-
const scope = unread
|
|
264
|
-
? ["m.id > MAX(?, (SELECT read_cursor FROM board_sessions WHERE session_id = ?))", UNREAD]
|
|
265
|
-
: ["m.id > ?"];
|
|
266
|
-
const bindings: Array<number | string> = [input.after ?? 0];
|
|
267
|
-
if (unread) bindings.push(this.identity.sessionId, this.identity.sessionId);
|
|
268
|
-
if (input.channel !== undefined) { scope.push("m.channel = ?"); bindings.push(input.channel); }
|
|
269
|
-
if (input.thread !== undefined) { scope.push("m.thread = ?"); bindings.push(input.thread); }
|
|
270
|
-
const rows = this.db.query<MessageRow, Array<number | string>>(`SELECT m.* FROM board_messages m
|
|
271
|
-
WHERE ${scope.join(" AND ")} ORDER BY m.id LIMIT ?`).all(...bindings, limit);
|
|
272
|
-
this.markRead(rows.map(row => row.id));
|
|
273
|
-
return rows.map(message);
|
|
274
|
-
}).immediate();
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
subscribe(channels: string[]): BoardState {
|
|
278
|
-
if (!Array.isArray(channels) || channels.length > 128) throw new Error("Board subscriptions must contain at most 128 channels");
|
|
279
|
-
const unique = [...new Set(channels)].sort();
|
|
280
|
-
for (const channel of unique) channelName(channel);
|
|
281
|
-
this.db.transaction(() => {
|
|
282
|
-
this.requireMembership();
|
|
283
|
-
const { sessionId, actor, role } = this.identity;
|
|
284
|
-
const previous = new Set(this.subscriptions());
|
|
285
|
-
const requested = new Set(unique);
|
|
286
|
-
for (const channel of previous) {
|
|
287
|
-
if (!requested.has(channel)) this.db.query("DELETE FROM board_subscriptions WHERE session_id = ? AND channel = ?")
|
|
288
|
-
.run(sessionId, channel);
|
|
289
|
-
}
|
|
290
|
-
const start = role === "lane" ? this.noticePosition() : 0;
|
|
291
|
-
let rewind = start;
|
|
292
|
-
for (const channel of unique) {
|
|
293
|
-
if (previous.has(channel)) continue;
|
|
294
|
-
this.db.query("INSERT INTO board_subscriptions(session_id, channel) VALUES (?, ?)")
|
|
295
|
-
.run(sessionId, channel);
|
|
296
|
-
// Reopening eligibility can reveal older undelivered posts. Seek just
|
|
297
|
-
// this channel; precise receipts still exclude bodies or headers seen.
|
|
298
|
-
if (rewind !== 0) {
|
|
299
|
-
const older = this.db.query<{ id: number }, [string, string, number, string, string]>(`
|
|
300
|
-
SELECT m.id FROM board_messages m
|
|
301
|
-
WHERE m.channel = ? AND m.id > (SELECT read_cursor FROM board_sessions WHERE session_id = ?)
|
|
302
|
-
AND m.id <= ? AND m.actor <> ? AND ${UNNOTIFIED}
|
|
303
|
-
ORDER BY m.id LIMIT 1`).get(channel, sessionId, rewind, actor, sessionId);
|
|
304
|
-
if (older) rewind = older.id - 1;
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
if (rewind < start) this.setNoticePosition(rewind);
|
|
308
|
-
}).immediate();
|
|
309
|
-
return this.state();
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
/** Header delivery is independent of reading. No timers, callbacks, or executor live here. */
|
|
313
|
-
notices(limit = 50): BoardNotice[] {
|
|
314
|
-
pageSize(limit);
|
|
315
|
-
return this.db.transaction(() => {
|
|
316
|
-
this.requireMembership();
|
|
317
|
-
const { sessionId, actor, role } = this.identity;
|
|
318
|
-
const start = this.noticePosition();
|
|
319
|
-
const end = this.db.query<{ id: number }, []>("SELECT COALESCE(MAX(id), 0) AS id FROM board_messages").get()?.id ?? 0;
|
|
320
|
-
if (start >= end) return [];
|
|
321
|
-
const eligibility = role === "head" ? "m.role = 'lane'" : `(
|
|
322
|
-
EXISTS (SELECT 1 FROM board_mentions n WHERE n.message_id = m.id AND n.actor = ?) OR
|
|
323
|
-
EXISTS (SELECT 1 FROM board_subscriptions s WHERE s.session_id = ? AND s.channel = m.channel))`;
|
|
324
|
-
const audience = role === "head" ? [] : [actor, sessionId];
|
|
325
|
-
const rows = this.db.query<NoticeRow, Array<number | string>>(`
|
|
326
|
-
SELECT m.id, m.session_id, m.actor, m.role, m.channel, m.thread, m.reply_to, m.mentions, m.created_at
|
|
327
|
-
FROM board_messages m WHERE m.id > ? AND m.actor <> ? AND ${eligibility} AND ${UNNOTIFIED}
|
|
328
|
-
ORDER BY m.id LIMIT ?`).all(start, actor, ...audience, sessionId, limit);
|
|
329
|
-
const last = rows.at(-1);
|
|
330
|
-
if (last) {
|
|
331
|
-
this.db.query(`INSERT INTO board_receipts(session_id, message_id, noticed_at)
|
|
332
|
-
SELECT ?, value, ? FROM json_each(?) WHERE true
|
|
333
|
-
ON CONFLICT(session_id, message_id) DO UPDATE SET noticed_at = excluded.noticed_at`)
|
|
334
|
-
.run(sessionId, Date.now(), JSON.stringify(rows.map(row => row.id)));
|
|
335
|
-
this.db.query("UPDATE board_sessions SET notice_cursor = MAX(notice_cursor, ?) WHERE session_id = ?")
|
|
336
|
-
.run(last.id, sessionId);
|
|
337
|
-
}
|
|
338
|
-
// Unlike notice_cursor, this is the examined prefix under the current
|
|
339
|
-
// eligibility rules, including irrelevant posts. A full page proves
|
|
340
|
-
// only through its last row; subscribe rewinds for newly relevant gaps.
|
|
341
|
-
this.setNoticePosition(last && rows.length === limit ? last.id : end);
|
|
342
|
-
return rows.map(notice);
|
|
343
|
-
}).immediate();
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
state(): BoardState {
|
|
347
|
-
this.requireMembership();
|
|
348
|
-
const row = this.db.query("SELECT read_cursor, notice_cursor FROM board_sessions WHERE session_id = ?")
|
|
349
|
-
.get(this.identity.sessionId) as { read_cursor: number; notice_cursor: number };
|
|
350
|
-
// Seek to the next distinct channel instead of scanning every message in
|
|
351
|
-
// the channel index for each explicit history or subscription response.
|
|
352
|
-
const channels = this.db.query<{ channel: string }, []>(`
|
|
353
|
-
WITH RECURSIVE channels(channel) AS (
|
|
354
|
-
SELECT MIN(channel) FROM board_messages
|
|
355
|
-
UNION ALL
|
|
356
|
-
SELECT (SELECT channel FROM board_messages WHERE channel > c.channel ORDER BY channel LIMIT 1)
|
|
357
|
-
FROM channels c WHERE c.channel IS NOT NULL
|
|
358
|
-
) SELECT channel FROM channels WHERE channel IS NOT NULL`).all();
|
|
359
|
-
return { identity: { ...this.identity }, readCursor: row.read_cursor, noticeCursor: row.notice_cursor,
|
|
360
|
-
subscriptions: this.subscriptions(),
|
|
361
|
-
channels: [...new Set(["general", this.repositoryChannel, ...channels.map(item => item.channel)])].sort() };
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
membership(): Readonly<BoardIdentity> {
|
|
365
|
-
this.requireMembership();
|
|
366
|
-
return this.identity;
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
close(): void {
|
|
370
|
-
if (this.closed) return;
|
|
371
|
-
this.closed = true;
|
|
372
|
-
this.db.close();
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
private get(id: number): BoardMessage | null {
|
|
376
|
-
const row = this.db.query("SELECT * FROM board_messages WHERE id = ?").get(id) as MessageRow | null;
|
|
377
|
-
return row ? message(row) : null;
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
private subscriptions(): string[] {
|
|
381
|
-
return this.db.query<{ channel: string }, [string]>("SELECT channel FROM board_subscriptions WHERE session_id = ? ORDER BY channel")
|
|
382
|
-
.all(this.identity.sessionId).map(row => row.channel);
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
private noticePosition(): number {
|
|
386
|
-
const row = this.db.query<{ position: number }, [string]>(`SELECT MAX(s.read_cursor, COALESCE(n.position, 0)) AS position
|
|
387
|
-
FROM board_sessions s LEFT JOIN board_notice_scans n USING(session_id) WHERE s.session_id = ?`)
|
|
388
|
-
.get(this.identity.sessionId);
|
|
389
|
-
if (!row) throw new BoardMembershipError();
|
|
390
|
-
return row.position;
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
private setNoticePosition(position: number): void {
|
|
394
|
-
this.db.query(`INSERT INTO board_notice_scans(session_id, position) VALUES (?, ?)
|
|
395
|
-
ON CONFLICT(session_id) DO UPDATE SET position = excluded.position`).run(this.identity.sessionId, position);
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
private requireMembership(): number {
|
|
399
|
-
if (this.closed) throw new BoardMembershipError();
|
|
400
|
-
let generation: number;
|
|
401
|
-
const tables = this.db.query("SELECT name FROM sqlite_master WHERE type = 'table' AND name IN ('metadata', 'lanes')")
|
|
402
|
-
.all() as Array<{ name: string }>;
|
|
403
|
-
if (this.identity.role === "head") {
|
|
404
|
-
if (!tables.some(table => table.name === "metadata")) throw new BoardMembershipError();
|
|
405
|
-
const session = this.db.query("SELECT value FROM metadata WHERE key = 'main:sessionId'")
|
|
406
|
-
.get() as { value: string } | null;
|
|
407
|
-
const currentGeneration = this.db.query("SELECT value FROM metadata WHERE key = 'main:generation'")
|
|
408
|
-
.get() as { value: string } | null;
|
|
409
|
-
const currentSessionFile = this.db.query<{ value: string }, [string]>("SELECT value FROM metadata WHERE key = ?")
|
|
410
|
-
.get(HEAD_SESSION_FILE_KEY)?.value ?? null;
|
|
411
|
-
const owner = this.db.query("SELECT value FROM metadata WHERE key = 'gateway:head'")
|
|
412
|
-
.get() as { value: string } | null;
|
|
413
|
-
let ownedHead: { pid?: number; sessionId?: string; sessionFile?: string } | null;
|
|
414
|
-
try { ownedHead = JSON.parse(owner?.value ?? "null"); }
|
|
415
|
-
catch { throw new BoardMembershipError(); }
|
|
416
|
-
// main:sessionId and its file survive shutdown. Only the actual process
|
|
417
|
-
// still owned by this Gateway is a member, not a standalone resumed copy.
|
|
418
|
-
// Keep that process admitted during a transient Gateway disconnection.
|
|
419
|
-
if (!ownedHead || ownedHead.pid !== process.pid || ownedHead.sessionId !== this.identity.sessionId ||
|
|
420
|
-
typeof ownedHead.sessionFile !== "string" || canonicalSessionFile(ownedHead.sessionFile) !== this.sessionFile) {
|
|
421
|
-
throw new BoardMembershipError();
|
|
422
|
-
}
|
|
423
|
-
let registeredFile: string;
|
|
424
|
-
try { registeredFile = canonicalSessionFile(activeHeadSessionFile(this.stateDirectory, currentSessionFile)); }
|
|
425
|
-
catch { throw new BoardMembershipError(); }
|
|
426
|
-
if (session?.value !== this.identity.sessionId || this.sessionFile !== registeredFile) throw new BoardMembershipError();
|
|
427
|
-
generation = Number(currentGeneration?.value ?? "0");
|
|
428
|
-
} else {
|
|
429
|
-
if (!tables.some(table => table.name === "lanes")) throw new BoardMembershipError();
|
|
430
|
-
// A remote PID/file pair can have a local namesake. It cannot grant
|
|
431
|
-
// membership to a process opening this machine's SQLite board.
|
|
432
|
-
const row = this.db.query<{ generation: number; data: string; remote?: string | null }, [string]>(
|
|
433
|
-
"SELECT * FROM lanes WHERE id = ?").get(this.identity.actor);
|
|
434
|
-
if (!row || row.remote != null) throw new BoardMembershipError();
|
|
435
|
-
const lane = JSON.parse(row.data) as Lane;
|
|
436
|
-
if (lane.id !== this.identity.actor || lane.sessionId !== this.identity.sessionId ||
|
|
437
|
-
canonicalSessionFile(lane.sessionFile) !== this.sessionFile || lane.pid !== process.pid ||
|
|
438
|
-
(lane.workState !== "open" && lane.workState !== "paused") ||
|
|
439
|
-
(lane.runtimeState !== "running" && lane.runtimeState !== "idle") || lane.generation !== row.generation) {
|
|
440
|
-
throw new BoardMembershipError();
|
|
441
|
-
}
|
|
442
|
-
generation = row.generation;
|
|
443
|
-
}
|
|
444
|
-
if (!Number.isSafeInteger(generation) || generation < 0 ||
|
|
445
|
-
(this.generation !== undefined && generation !== this.generation)) throw new BoardMembershipError();
|
|
446
|
-
return generation;
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
private markRead(ids: number[]): void {
|
|
450
|
-
if (!ids.length) return;
|
|
451
|
-
const { sessionId } = this.identity;
|
|
452
|
-
this.db.query(`INSERT INTO board_receipts(session_id, message_id, read_at)
|
|
453
|
-
SELECT ?, value, ? FROM json_each(?) WHERE true
|
|
454
|
-
ON CONFLICT(session_id, message_id) DO UPDATE SET read_at = excluded.read_at`)
|
|
455
|
-
.run(sessionId, Date.now(), JSON.stringify(ids));
|
|
456
|
-
// Only a contiguous, exactly observed prefix advances the read cursor. Filters,
|
|
457
|
-
// pagination, replies and a high notice cursor cannot acknowledge unseen gaps.
|
|
458
|
-
const gap = this.db.query<{ id: number }, [string, string]>(`SELECT m.id FROM board_messages m
|
|
459
|
-
WHERE m.id > (SELECT read_cursor FROM board_sessions WHERE session_id = ?) AND ${UNREAD}
|
|
460
|
-
ORDER BY m.id LIMIT 1`).get(sessionId, sessionId);
|
|
461
|
-
const end = !gap
|
|
462
|
-
? this.db.query<{ id: number }, []>("SELECT COALESCE(MAX(id), 0) AS id FROM board_messages").get()?.id ?? 0
|
|
463
|
-
: gap.id - 1;
|
|
464
|
-
this.db.query("UPDATE board_sessions SET read_cursor = ? WHERE session_id = ? AND read_cursor < ?")
|
|
465
|
-
.run(end, sessionId, end);
|
|
466
|
-
}
|
|
467
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export {};
|
|
2
|
-
|
|
3
|
-
try {
|
|
4
|
-
const [, , operation, path] = process.argv;
|
|
5
|
-
if (operation !== "session-id" || !path?.startsWith("/")) throw new Error("Expected an absolute session path");
|
|
6
|
-
const { readSessionHeaderId } = await import("@oh-my-pi/pi-coding-agent/session/session-loader");
|
|
7
|
-
const id = await readSessionHeaderId(path);
|
|
8
|
-
process.stdout.write(`GATEWAY_HOST ${JSON.stringify(id ?? null)}\n`);
|
|
9
|
-
} catch {
|
|
10
|
-
// Do not put private SDK/session diagnostics on the Gateway channel.
|
|
11
|
-
console.error("Gateway Host SDK operation failed");
|
|
12
|
-
process.exitCode = 1;
|
|
13
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import catalog from "./messenger-command-catalog.json" with { type: "json" };
|
|
2
|
-
|
|
3
|
-
/** Owner controls and platform-specific registration metadata shared with the native Gateway. */
|
|
4
|
-
export const MESSENGER_COMMAND_CATALOG: readonly {
|
|
5
|
-
readonly name: string;
|
|
6
|
-
readonly description: string;
|
|
7
|
-
readonly text?: string;
|
|
8
|
-
readonly discordOnly?: boolean;
|
|
9
|
-
readonly discord?: {
|
|
10
|
-
readonly description: string;
|
|
11
|
-
readonly text: boolean;
|
|
12
|
-
};
|
|
13
|
-
}[] = catalog;
|
|
14
|
-
|
|
15
|
-
export const MESSENGER_COMMANDS = MESSENGER_COMMAND_CATALOG.filter(command => !command.discordOnly);
|
package/src/native-sessions.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import * as fs from "node:fs/promises";
|
|
2
|
-
import { dirname, join, resolve } from "node:path";
|
|
3
|
-
import { SessionManager } from "@oh-my-pi/pi-coding-agent/session/session-manager";
|
|
4
|
-
import { readSessionInfo } from "@oh-my-pi/pi-coding-agent/session/session-listing";
|
|
5
|
-
|
|
6
|
-
/** Stock OMP follows leaf session links for discovery and writes through them. */
|
|
7
|
-
export async function publishNativeSession(sessionFile: string, cwd: string, expectedId?: string): Promise<string | undefined> {
|
|
8
|
-
const info = await readSessionInfo(sessionFile);
|
|
9
|
-
if (!info) return;
|
|
10
|
-
if (expectedId !== undefined && (info.id !== expectedId || info.cwd !== cwd))
|
|
11
|
-
throw new Error("Refusing to publish a journal with a different managed session identity");
|
|
12
|
-
const source = await fs.realpath(sessionFile);
|
|
13
|
-
const directory = SessionManager.getDefaultSessionDir(cwd);
|
|
14
|
-
const target = join(directory, `${info.created.toISOString().replace(/[:.]/g, "-")}_${info.id}.jsonl`);
|
|
15
|
-
if (target === source) return target;
|
|
16
|
-
|
|
17
|
-
const link = async (original: string, destination: string) => {
|
|
18
|
-
try { await fs.symlink(original, destination); }
|
|
19
|
-
catch (error) {
|
|
20
|
-
if ((error as NodeJS.ErrnoException).code !== "EEXIST") throw error;
|
|
21
|
-
const existing = await fs.readlink(destination).catch(() => undefined);
|
|
22
|
-
if (!existing || resolve(dirname(destination), existing) !== original)
|
|
23
|
-
throw new Error(`Native session discovery path already belongs to another file: ${destination}`);
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
// The resumed session must keep its original spill artifacts and child journals.
|
|
27
|
-
if (source.endsWith(".jsonl")) {
|
|
28
|
-
const artifacts = source.slice(0, -".jsonl".length);
|
|
29
|
-
await fs.mkdir(artifacts, { recursive: true, mode: 0o700 });
|
|
30
|
-
await link(artifacts, target.slice(0, -".jsonl".length));
|
|
31
|
-
}
|
|
32
|
-
await link(source, target);
|
|
33
|
-
return target;
|
|
34
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|