omp-superagent 0.0.0-stage → 0.1.2
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 +1502 -0
- package/LICENSE +21 -0
- package/README.ko.md +198 -0
- package/README.md +224 -2
- package/THIRD_PARTY_NOTICES.md +388 -0
- package/assets/architecture.mmd +24 -0
- package/assets/architecture.svg +126 -0
- package/assets/superagent-avatar.jpg +0 -0
- package/assets/superagent-mascot.webp +0 -0
- package/config.example.json +26 -0
- package/docs/OPERATIONS.md +1178 -0
- package/docs/discord-voice.md +96 -0
- package/docs/releases/0.1.0.md +222 -0
- package/docs/releases/0.1.1.md +60 -0
- package/docs/releases/0.1.2.md +53 -0
- package/package.json +65 -4
- package/scripts/ci.ts +33 -0
- package/scripts/prepare-ulw.ts +18 -0
- package/scripts/release.ts +58 -0
- package/scripts/setup.sh +25 -0
- package/scripts/test-omp.sh +36 -0
- package/skills/head/SKILL.md +100 -0
- package/skills/head/references/model-selection.md +83 -0
- package/skills/head/references/routing.md +181 -0
- package/skills/head/references/supervision.md +122 -0
- package/skills/lane/SKILL.md +66 -0
- package/skills/lane/references/workflow.md +95 -0
- package/src/autostart.ts +295 -0
- package/src/board-extension.ts +217 -0
- package/src/board.ts +396 -0
- package/src/cli.ts +253 -0
- package/src/codex-live-bridge.py +73 -0
- package/src/codex-live.ts +244 -0
- package/src/codex-voice-requirements.txt +5 -0
- package/src/codex_live_auth.py +192 -0
- package/src/codex_live_media.py +219 -0
- package/src/codex_live_provider.py +192 -0
- package/src/config.ts +266 -0
- package/src/contracts.ts +381 -0
- package/src/credentials.ts +172 -0
- package/src/decision-tool.ts +59 -0
- package/src/decisions.ts +143 -0
- package/src/delivery.ts +17 -0
- package/src/dialog.ts +73 -0
- package/src/discord-command-registration.ts +201 -0
- package/src/discord-commands.ts +29 -0
- package/src/discord-context.ts +118 -0
- package/src/discord-markdown.ts +172 -0
- package/src/discord-voice-draft.ts +124 -0
- package/src/discord-voice-link.ts +270 -0
- package/src/discord-voice.ts +150 -0
- package/src/discord.ts +1012 -0
- package/src/extension.ts +446 -0
- package/src/gateway-client.ts +229 -0
- package/src/gateway-protocol.ts +85 -0
- package/src/gateway-restart.ts +151 -0
- package/src/gateway-server.ts +440 -0
- package/src/gateway-store.ts +251 -0
- package/src/gateway.ts +654 -0
- package/src/head-recovery.ts +61 -0
- package/src/host-broker-services.ts +108 -0
- package/src/host-extension.ts +561 -0
- package/src/host-owner.ts +366 -0
- package/src/host-protocol.ts +144 -0
- package/src/host-services.ts +54 -0
- package/src/host.ts +415 -0
- package/src/installed-omp.ts +71 -0
- package/src/lane-extension.ts +184 -0
- package/src/lane-models.ts +75 -0
- package/src/lane-report.ts +70 -0
- package/src/lane-rows.ts +12 -0
- package/src/managed-ulw-probe.ts +172 -0
- package/src/managed-ulw.ts +471 -0
- package/src/message-order.ts +21 -0
- package/src/messenger-commands.ts +16 -0
- package/src/messengers.ts +143 -0
- package/src/native-presets.ts +370 -0
- package/src/native-sessions.ts +32 -0
- package/src/native-settings.ts +131 -0
- package/src/openai-live.ts +377 -0
- package/src/pr-github-schema.ts +110 -0
- package/src/pr-github.ts +170 -0
- package/src/pr-watch.ts +200 -0
- package/src/repository.ts +12 -0
- package/src/runtime.ts +4229 -0
- package/src/setup-judge.ts +34 -0
- package/src/setup-memory.ts +39 -0
- package/src/setup-profiles.ts +84 -0
- package/src/setup.ts +300 -0
- package/src/slack-command-registration.ts +217 -0
- package/src/slack-commands.ts +18 -0
- package/src/slack.ts +779 -0
- package/src/store.ts +862 -0
- package/src/telegram-command-registration.ts +155 -0
- package/src/telegram.ts +677 -0
- package/src/workflow.ts +94 -0
- package/upstream/ulw.json +9 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import type { HeadRecoveryAttempt } from "./contracts";
|
|
3
|
+
|
|
4
|
+
const object = (value: unknown): Record<string, unknown> =>
|
|
5
|
+
value !== null && typeof value === "object" ? value as Record<string, unknown> : {};
|
|
6
|
+
|
|
7
|
+
/** Only journal identities and native outcome fields leave this evidence reader. */
|
|
8
|
+
export function headRecoveryEvidence(entries: unknown[], owner: Pick<HeadRecoveryAttempt,
|
|
9
|
+
"sessionId" | "sessionFile" | "requestId" | "cursor">, boundary?: string) {
|
|
10
|
+
const journal = entries.map(object);
|
|
11
|
+
const start = owner.cursor === null ? -1 : journal.findIndex(entry => entry.id === owner.cursor);
|
|
12
|
+
const end = boundary === undefined ? journal.length - 1 : journal.findIndex(entry => entry.id === boundary);
|
|
13
|
+
if (owner.cursor !== null && start < 0 || end <= start || typeof journal[end]?.id !== "string") return null;
|
|
14
|
+
const slice = journal.slice(start + 1, end + 1);
|
|
15
|
+
const matches = (entry: Record<string, unknown>, type: string) => entry.type === "custom" && entry.customType === type
|
|
16
|
+
&& object(entry.data).sessionId === owner.sessionId && object(entry.data).sessionFile === owner.sessionFile;
|
|
17
|
+
const receipts = slice.filter(entry => matches(entry, "rpc_prompt_result"));
|
|
18
|
+
const receiptsForRequest = receipts.filter(entry => object(object(entry.data).frame).id === owner.requestId);
|
|
19
|
+
if (receiptsForRequest.length !== 1 || receipts.length !== 1) return null;
|
|
20
|
+
const receipt = receiptsForRequest[0]!;
|
|
21
|
+
const frame = object(object(receipt.data).frame);
|
|
22
|
+
const starts = slice.filter(entry => matches(entry, "rpc_agent_start"));
|
|
23
|
+
const latestStart = starts.at(-1);
|
|
24
|
+
const latestStartIndex = latestStart ? slice.indexOf(latestStart) : -1;
|
|
25
|
+
// Another submitted user message is an ownership boundary, even if its RPC
|
|
26
|
+
// receipt has not arrived. Do not borrow its assistant outcome.
|
|
27
|
+
const users = slice.filter(entry => entry.type === "message" && object(entry.message).role === "user");
|
|
28
|
+
const firstAssistantIndex = slice.findIndex(entry => entry.type === "message" && object(entry.message).role === "assistant");
|
|
29
|
+
if (users.length > 1 || users.some(entry => firstAssistantIndex >= 0 && slice.indexOf(entry) > firstAssistantIndex)) return null;
|
|
30
|
+
const assistants = slice.slice(latestStartIndex + 1).filter(entry => entry.type === "message"
|
|
31
|
+
&& object(entry.message).role === "assistant");
|
|
32
|
+
const latestAssistant = assistants.at(-1);
|
|
33
|
+
const latestRunStatus = object(latestAssistant?.message).stopReason;
|
|
34
|
+
let outcome: "done" | "cancelled" | undefined;
|
|
35
|
+
const receiptData = object(receipt.data);
|
|
36
|
+
const startData = object(latestStart?.data);
|
|
37
|
+
const receiptAfterStart = typeof receiptData.runOrdinal === "number" && typeof startData.runOrdinal === "number"
|
|
38
|
+
&& receiptData.hostPid === startData.hostPid
|
|
39
|
+
? receiptData.runOrdinal >= startData.runOrdinal
|
|
40
|
+
: slice.indexOf(receipt) > latestStartIndex;
|
|
41
|
+
if (frame.status === "aborted" && (!latestStart || receiptAfterStart)) outcome = "cancelled";
|
|
42
|
+
if (frame.status === "completed") {
|
|
43
|
+
if (frame.agentInvoked === false && !latestStart) outcome = "done";
|
|
44
|
+
else if (latestStart && (latestRunStatus === "stop" || latestRunStatus === "length")) outcome = "done";
|
|
45
|
+
else if (latestStart && latestRunStatus === "aborted") outcome = "cancelled";
|
|
46
|
+
}
|
|
47
|
+
const selected = [receipt, ...starts, ...assistants];
|
|
48
|
+
if (selected.some(entry => typeof entry.id !== "string")) return null;
|
|
49
|
+
const entryIds = [...new Set(selected.map(entry => String(entry.id)))];
|
|
50
|
+
const proof = { entryIds, receiptStatus: String(frame.status), latestRunStatus: latestRunStatus ?? null,
|
|
51
|
+
outcome: outcome ?? null };
|
|
52
|
+
return { ...proof, boundary: String(journal[end]!.id),
|
|
53
|
+
fingerprint: createHash("sha256").update(JSON.stringify(slice.map(entry => [
|
|
54
|
+
entry.id, entry.type, entry.customType,
|
|
55
|
+
matches(entry, "rpc_prompt_result") ? object(entry.data).frame : null,
|
|
56
|
+
matches(entry, "rpc_prompt_result") || matches(entry, "rpc_agent_start")
|
|
57
|
+
? [object(entry.data).hostPid ?? null, object(entry.data).instanceKey ?? null, object(entry.data).runOrdinal ?? null] : null,
|
|
58
|
+
entry.type === "message" ? object(entry.message).role : null,
|
|
59
|
+
entry.type === "message" ? object(entry.message).stopReason : null,
|
|
60
|
+
]))).digest("hex") };
|
|
61
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { readFile, readdir, realpath } from "node:fs/promises";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { FileLock, IpcConnection, ipcEndpoint } from "@oh-my-pi/pi-natives";
|
|
4
|
+
import { getDaemonDir, getDaemonRuntimeDir } from "@oh-my-pi/pi-utils/dirs";
|
|
5
|
+
import { hasFsCode } from "@oh-my-pi/pi-utils";
|
|
6
|
+
import { Type, type Static } from "@sinclair/typebox";
|
|
7
|
+
import { Value } from "@sinclair/typebox/value";
|
|
8
|
+
import type { ServiceUnit } from "./host-protocol";
|
|
9
|
+
|
|
10
|
+
// Stock OMP v18.22.2 launch/{broker,client,paths,protocol}. The stock ps client
|
|
11
|
+
// can start a broker when a connection fails; inventory here must never do so.
|
|
12
|
+
const snapshot = Type.Object({
|
|
13
|
+
id: Type.String({ minLength: 1 }),
|
|
14
|
+
name: Type.String({ minLength: 1 }),
|
|
15
|
+
owner: Type.Optional(Type.String({ minLength: 1 })),
|
|
16
|
+
state: Type.Union((["starting", "running", "ready", "restarting", "stopping", "exited", "failed"] as const)
|
|
17
|
+
.map(state => Type.Literal(state))),
|
|
18
|
+
pid: Type.Optional(Type.Integer({ minimum: 1 })),
|
|
19
|
+
startedAt: Type.Number(),
|
|
20
|
+
exitedAt: Type.Optional(Type.Number()),
|
|
21
|
+
restartCount: Type.Integer({ minimum: 0 }),
|
|
22
|
+
});
|
|
23
|
+
const reply = Type.Union([
|
|
24
|
+
Type.Object({ id: Type.String(), ok: Type.Literal(true), result: Type.Union([
|
|
25
|
+
Type.Object({ op: Type.Literal("list"), daemons: Type.Array(snapshot) }),
|
|
26
|
+
Type.Object({ op: Type.Literal("describe"), daemon: snapshot }),
|
|
27
|
+
]) }),
|
|
28
|
+
Type.Object({ id: Type.String(), ok: Type.Literal(false), error: Type.String() }),
|
|
29
|
+
]);
|
|
30
|
+
const stored = Type.Object({ daemon: snapshot });
|
|
31
|
+
|
|
32
|
+
function unit(row: Static<typeof snapshot>, supervised: boolean): ServiceUnit {
|
|
33
|
+
const { id, name, owner, state, pid, startedAt, exitedAt, restartCount } = row;
|
|
34
|
+
return { id, key: name, state, pids: pid === undefined ? [] : [pid], startedAt, restartCount, supervised,
|
|
35
|
+
...(owner === undefined ? {} : { owner }), ...(exitedAt === undefined ? {} : { exitedAt }) };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function directories(path: string): Promise<string[]> {
|
|
39
|
+
try { return (await readdir(path, { withFileTypes: true })).filter(entry => entry.isDirectory()).map(entry => entry.name).sort(); }
|
|
40
|
+
catch (error) {
|
|
41
|
+
if (hasFsCode(error, "ENOENT")) return [];
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async function readScope(runtimeDir: string, key?: string): Promise<ServiceUnit[]> {
|
|
47
|
+
const lease = join(runtimeDir, "broker.pid");
|
|
48
|
+
const endpoint = ipcEndpoint(runtimeDir, "broker");
|
|
49
|
+
let socket: IpcConnection;
|
|
50
|
+
try { socket = await IpcConnection.connect(endpoint, { framing: "lines", timeoutMs: 500 }); }
|
|
51
|
+
catch (error) {
|
|
52
|
+
if (!(hasFsCode(error, "ENOENT") || hasFsCode(error, "ECONNREFUSED")) || FileLock.isHeld(lease))
|
|
53
|
+
throw new Error("Cannot confirm native broker service ownership");
|
|
54
|
+
const root = join(runtimeDir, "daemons");
|
|
55
|
+
const offline = await Promise.all((await directories(root)).map(async name => {
|
|
56
|
+
const record: unknown = JSON.parse(await readFile(join(root, name, "meta.json"), "utf8"));
|
|
57
|
+
if (!Value.Check(stored, record)) throw new Error("Invalid persisted native broker service");
|
|
58
|
+
// Keep the recorded state, never turn a stale running row into proof of an exit.
|
|
59
|
+
return unit(record.daemon, false);
|
|
60
|
+
}));
|
|
61
|
+
if (FileLock.isHeld(lease)) throw new Error("Native broker started during service observation");
|
|
62
|
+
return key === undefined ? offline : offline.filter(row => row.key === key);
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
if (!FileLock.isHeld(lease)) throw new Error("Native broker ownership lease is unavailable");
|
|
66
|
+
const token = (await readFile(join(runtimeDir, "broker.token"), "utf8")).trim();
|
|
67
|
+
if (!token) throw new Error("Native broker authentication is unavailable");
|
|
68
|
+
const id = crypto.randomUUID();
|
|
69
|
+
const { promise, resolve, reject } = Promise.withResolvers<ServiceUnit[]>();
|
|
70
|
+
const timer = setTimeout(() => reject(new Error("Native broker inventory timed out")), 2_000);
|
|
71
|
+
try {
|
|
72
|
+
socket.start(line => {
|
|
73
|
+
try {
|
|
74
|
+
const response: unknown = JSON.parse(line);
|
|
75
|
+
if (!Value.Check(reply, response) || response.id !== id || !FileLock.isHeld(lease))
|
|
76
|
+
throw new Error("Native broker inventory was not confirmed");
|
|
77
|
+
if (key === undefined && response.ok && response.result.op === "list") {
|
|
78
|
+
resolve(response.result.daemons.map(row => unit(row, true)));
|
|
79
|
+
} else if (key !== undefined && response.ok && response.result.op === "describe" && response.result.daemon.name === key) {
|
|
80
|
+
resolve([unit(response.result.daemon, true)]);
|
|
81
|
+
} else if (key !== undefined && !response.ok
|
|
82
|
+
&& (response.error === `Unknown daemon ${key}` || response.error.startsWith(`Unknown daemon ${key}. Available: `))) {
|
|
83
|
+
resolve([]);
|
|
84
|
+
} else throw new Error("Native broker inventory was not confirmed");
|
|
85
|
+
} catch (error) { reject(error); }
|
|
86
|
+
}, () => reject(new Error("Native broker closed before inventory was confirmed")));
|
|
87
|
+
// The broker's list caps terminal rows. Named launch correlation needs
|
|
88
|
+
// its exact row even if many other services have just finished.
|
|
89
|
+
const operation = key === undefined ? { op: "list" } : { op: "describe", name: key };
|
|
90
|
+
socket.send(JSON.stringify({ id, token, operation }));
|
|
91
|
+
return await promise;
|
|
92
|
+
} finally { clearTimeout(timer); }
|
|
93
|
+
} finally { socket.destroy(); }
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Use the same profile as the ordinary pipe owner, without acquiring a broker lease. */
|
|
97
|
+
export function brokerServiceInventory(hostCwd: string) {
|
|
98
|
+
const projects = dirname(getDaemonRuntimeDir(hostCwd));
|
|
99
|
+
const globals = join(dirname(getDaemonDir()), "daemons", "global");
|
|
100
|
+
return async (projectDir?: string, key?: string): Promise<ServiceUnit[]> => {
|
|
101
|
+
if (projectDir !== undefined) return readScope(getDaemonRuntimeDir(projectDir), key);
|
|
102
|
+
const [projectScopes, globalScopes] = await Promise.all([directories(projects), directories(globals)]);
|
|
103
|
+
return (await Promise.all([
|
|
104
|
+
...projectScopes.filter(name => /^[0-9a-f]{16}$/.test(name)).map(name => readScope(join(projects, name))),
|
|
105
|
+
...globalScopes.map(async name => readScope(await realpath(join(globals, name)))),
|
|
106
|
+
])).flat();
|
|
107
|
+
};
|
|
108
|
+
}
|