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
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import type { Args } from "@oh-my-pi/pi-coding-agent/cli/args";
|
|
3
|
+
|
|
4
|
+
export function stockReplayRefusal(parsed: Args | null, sessionFile: string): string | undefined {
|
|
5
|
+
if (parsed?.mode !== "rpc-ui" || parsed.resume !== sessionFile)
|
|
6
|
+
return "HEAD wake requires an exact stock rpc-ui session launch";
|
|
7
|
+
if (parsed.fork !== undefined || parsed.continue || parsed.restore || parsed.noSession || parsed.fromClaude || parsed.fromCodex)
|
|
8
|
+
return "HEAD wake cannot combine competing stock session selectors";
|
|
9
|
+
if (parsed.maxTime !== undefined)
|
|
10
|
+
return "Stock --max-time starts a new deadline on launch; HEAD wake cannot restore its remaining time";
|
|
11
|
+
if (parsed.prewalk || parsed.prewalkInto !== undefined)
|
|
12
|
+
return "Stock --prewalk or --prewalk-into rearms one-shot planning on launch; HEAD wake cannot restore its prior state";
|
|
13
|
+
if (parsed.planYolo || parsed.planYoloInto !== undefined)
|
|
14
|
+
return "Stock --plan-yolo rearms autonomous planning on launch; HEAD wake cannot restore its prior state";
|
|
15
|
+
if (parsed.unrecognizedFlags.includes("--preset"))
|
|
16
|
+
return "Stock OMP has no --preset launch selector; an extension-owned --preset cannot be restored by HEAD wake";
|
|
17
|
+
if (parsed.goal !== undefined || parsed.messages.length || parsed.fileArgs.length
|
|
18
|
+
|| parsed.invalidFlagValues.length || parsed.unrecognizedFlags.length || parsed.unknownFlags.size)
|
|
19
|
+
return "HEAD wake cannot prove replay of stock startup input or extension-owned flags";
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function launchArgvHash(argv: readonly string[]): string {
|
|
23
|
+
return createHash("sha256").update(JSON.stringify(argv)).digest("hex");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** The helper has parsed these exact arguments before spawn. A wrapper may
|
|
27
|
+
* change them, and only the live extension runner knows which flags it owns. */
|
|
28
|
+
export function matchesPreparedLaunch(argv: readonly string[], prepared: unknown, flags?: ReadonlyMap<string, unknown>): boolean {
|
|
29
|
+
return typeof prepared === "string" && flags !== undefined && launchArgvHash(argv) === prepared
|
|
30
|
+
&& !argv.some(arg => arg.startsWith("--") && flags.has(arg.slice(2).split("=", 1)[0]));
|
|
31
|
+
}
|
|
@@ -6,8 +6,8 @@ import {
|
|
|
6
6
|
import { userInfo } from "node:os";
|
|
7
7
|
import { basename, dirname, isAbsolute, join, resolve } from "node:path";
|
|
8
8
|
import { fileURLToPath } from "node:url";
|
|
9
|
-
import { credentialEnvNames, type Config } from "
|
|
10
|
-
import { readCredentialFile, stagePrivateFile, validateCredential } from "
|
|
9
|
+
import { credentialEnvNames, type Config } from "../config/config";
|
|
10
|
+
import { readCredentialFile, stagePrivateFile, validateCredential } from "../config/credentials";
|
|
11
11
|
|
|
12
12
|
interface CommandResult { code: number; stdout: string; stderr: string }
|
|
13
13
|
/** Only OS identity and launchctl transport are injectable; never a production environment switch. */
|
|
@@ -79,7 +79,7 @@ function definition(config: Config, adapters: AutostartAdapters): Definition {
|
|
|
79
79
|
if (!isAbsolute(home) || !isAbsolute(executable)) throw new Error("Autostart requires absolute OS home and Bun paths");
|
|
80
80
|
return {
|
|
81
81
|
stateDir, label, home, executable, ompDirectory, configPath: resolve(config.path),
|
|
82
|
-
cliPath: fileURLToPath(new URL("
|
|
82
|
+
cliPath: fileURLToPath(new URL("../cli.ts", import.meta.url)),
|
|
83
83
|
plistPath: join(home, "Library", "LaunchAgents", `${label}.plist`),
|
|
84
84
|
path: searchPath(executable, ompDirectory),
|
|
85
85
|
target: `gui/${adapters.uid}/${label}`,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { addAbortListener } from "node:events";
|
|
2
|
-
import { requireGateway } from "
|
|
3
|
-
import { readCredentialFile, validateCredential } from "
|
|
2
|
+
import { requireGateway } from "../gateway/gateway-native";
|
|
3
|
+
import { readCredentialFile, validateCredential } from "../config/credentials";
|
|
4
4
|
|
|
5
5
|
type Credentials = { readonly bot: string; readonly manifest?: string };
|
|
6
6
|
export type OperatorRun = <T>(operation: string, request: unknown, credentials: Credentials, signal?: AbortSignal) => Promise<T>;
|
|
@@ -16,7 +16,7 @@ export async function inspectNativeJudge(cwd: string): Promise<JudgeConfiguratio
|
|
|
16
16
|
// Read-only settings intentionally skip legacy global migration. Only an
|
|
17
17
|
// effective higher-layer assignment can settle the role without it; in
|
|
18
18
|
// particular native project null falls through, unlike overlay null.
|
|
19
|
-
const { hasUnresolvedNativeLegacy } = await import("
|
|
19
|
+
const { hasUnresolvedNativeLegacy } = await import("../omp/native-settings");
|
|
20
20
|
if (await hasUnresolvedNativeLegacy(settings.getAgentDir())) return { status: "unknown" };
|
|
21
21
|
}
|
|
22
22
|
// Native modelRoles defaults to an empty record. This accessor normalizes
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Config } from "
|
|
2
|
-
import { validateCredential } from "
|
|
1
|
+
import type { Config } from "../config/config";
|
|
2
|
+
import { validateCredential } from "../config/credentials";
|
|
3
3
|
import { OperatorStartError, runOperator, type OperatorRun } from "./operator";
|
|
4
4
|
|
|
5
5
|
interface ProfileOptions {
|
|
@@ -6,16 +6,16 @@ import { dirname, isAbsolute, join, resolve } from "node:path";
|
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
7
|
import { isatty } from "node:tty";
|
|
8
8
|
import { setImmediate as yieldToSignals } from "node:timers/promises";
|
|
9
|
-
import { credentialEnvNames, hostPaths, parseConfig, type Config } from "
|
|
10
|
-
import { discoverInstalledOmp, inspectInstalledOmp } from "
|
|
9
|
+
import { credentialEnvNames, hostPaths, parseConfig, type Config } from "../config/config";
|
|
10
|
+
import { discoverInstalledOmp, inspectInstalledOmp } from "../omp/installed-omp";
|
|
11
11
|
import {
|
|
12
12
|
assertCredentialsUnchanged, readCredentialFile, serializeCredentials, stagePrivateFile,
|
|
13
13
|
validateCredential, writeCredentials,
|
|
14
|
-
} from "
|
|
15
|
-
import { applyConsentedMnemopi, canEnableGlobalMemory, inspectManagedMemory, memoryBlockReason } from "
|
|
14
|
+
} from "../config/credentials";
|
|
15
|
+
import { applyConsentedMnemopi, canEnableGlobalMemory, inspectManagedMemory, memoryBlockReason } from "../omp/managed-memory";
|
|
16
16
|
import { inspectNativeJudge } from "./setup-judge";
|
|
17
17
|
|
|
18
|
-
const root = resolve(dirname(fileURLToPath(import.meta.url)), "
|
|
18
|
+
const root = resolve(dirname(fileURLToPath(import.meta.url)), "../..");
|
|
19
19
|
|
|
20
20
|
class SetupCancelled extends Error {
|
|
21
21
|
constructor(saved = false) {
|
|
@@ -125,7 +125,8 @@ async function newConfig(terminal: Terminal, path: string): Promise<{ config: Co
|
|
|
125
125
|
if (!selected.length || selected.some(p => !["discord", "telegram", "slack"].includes(p)))
|
|
126
126
|
throw new Error("Select at least one supported messenger");
|
|
127
127
|
const raw: Record<string, unknown> = { ...template, command };
|
|
128
|
-
|
|
128
|
+
// Kakao needs an operator-run bridge; add its block manually (docs/kakao-bridge-protocol.md).
|
|
129
|
+
for (const platform of ["discord", "telegram", "slack", "kakao"]) delete raw[platform];
|
|
129
130
|
const list = async (label: string) => (await terminal.ask(`${label} (comma-separated; empty = deny groups / DM only): `))
|
|
130
131
|
.split(",").map(s => s.trim()).filter(Boolean);
|
|
131
132
|
for (const platform of selected) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { Type, type Static } from "@sinclair/typebox/type";
|
|
3
|
-
import type { StorePort } from "
|
|
3
|
+
import type { StorePort } from "../contracts";
|
|
4
4
|
import { PrReadError, parseWire, sha40 as sha } from "./pr-github-schema";
|
|
5
5
|
import { inspectIntakeComment, publishIntakeComment } from "./pr-intake-comment";
|
|
6
6
|
import { applyIntakeFix, parseIntakeFix, reconcileIntakeFix } from "./pr-intake-fix";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { normalizeIntakeRepository } from "
|
|
1
|
+
import { normalizeIntakeRepository } from "../cron/cron-pr-intake";
|
|
2
2
|
|
|
3
3
|
export const prModeEffects = {
|
|
4
4
|
review: "static review and a bounded GitHub PR comment",
|
|
@@ -24,7 +24,7 @@ const jobId = /^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/iu;
|
|
|
24
24
|
|
|
25
25
|
export function parsePrModeControl(argument: string): ModeCommand | null {
|
|
26
26
|
if (lineBreak.test(argument)) return null;
|
|
27
|
-
const match = /^pr-mode
|
|
27
|
+
const match = /^pr-mode\s+(?:(\S+)\s+)?(review|fix|merge)$/u.exec(argument.trim());
|
|
28
28
|
const [, selector, mode] = match ?? [];
|
|
29
29
|
if (mode !== "review" && mode !== "fix" && mode !== "merge") return null;
|
|
30
30
|
if (selector === undefined) return { target: null, mode };
|
|
@@ -36,7 +36,7 @@ export function parsePrModeControl(argument: string): ModeCommand | null {
|
|
|
36
36
|
export function prModeArgument(text: string): string | null {
|
|
37
37
|
if (lineBreak.test(text)) return null;
|
|
38
38
|
const command = text.trim();
|
|
39
|
-
const slash = /^\/cron
|
|
39
|
+
const slash = /^\/cron\s+(.+)$/u.exec(command)?.[1];
|
|
40
40
|
if (slash !== undefined) {
|
|
41
41
|
const parsed = parsePrModeControl(slash);
|
|
42
42
|
return parsed?.target ? `pr-mode ${parsed.target} ${parsed.mode}` : null;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
import { physicalRoute, routeKey, type Inbound, type InputRecord, type Lane, type Route, type StorePort } from "
|
|
3
|
-
import { compareMessageIds } from "
|
|
4
|
-
import type { CronJobs } from "
|
|
5
|
-
import type { CronPrCandidate, CronPrIntake } from "
|
|
6
|
-
import type { CronPrJob } from "
|
|
2
|
+
import { physicalRoute, routeKey, type Inbound, type InputRecord, type Lane, type Route, type StorePort } from "../contracts";
|
|
3
|
+
import { compareMessageIds } from "../routing/message-order";
|
|
4
|
+
import type { CronJobs } from "../cron/cron-jobs";
|
|
5
|
+
import type { CronPrCandidate, CronPrIntake } from "../cron/cron-pr-intake";
|
|
6
|
+
import type { CronPrJob } from "../cron/cron-jobs";
|
|
7
7
|
import { hasIntakeReplyRoute, intakeThreadKey, intakeStatusKey, intakeWorkId, intakeWorkPrefix } from "./pr-intake-work";
|
|
8
8
|
import { inspectIntakeMerge, mergeIntakePull } from "./pr-intake-github";
|
|
9
9
|
import { applyIntakeFix, intakeFixDigest, parseIntakeFix, reconcileIntakeFix } from "./pr-intake-fix";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { routeKey, type InputRecord, type StorePort } from "
|
|
1
|
+
import { routeKey, type InputRecord, type StorePort } from "../contracts";
|
|
2
2
|
|
|
3
3
|
// Controller receipts have no platform message/interaction and are never owner
|
|
4
4
|
// inputs. Only the restricted lane's exact native result has a delivery route.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { LaneModel } from "
|
|
2
|
-
import { acceptsRestrictedModelSelector, isLaneModel } from "
|
|
1
|
+
import type { LaneModel } from "../contracts";
|
|
2
|
+
import { acceptsRestrictedModelSelector, isLaneModel } from "../lane/lane-models";
|
|
3
3
|
|
|
4
4
|
const inferenceApis = new Set(["openai-completions", "openai-responses", "openai-codex-responses",
|
|
5
5
|
"azure-openai-responses", "anthropic-messages"]);
|
|
@@ -4,10 +4,10 @@ import { isDeepStrictEqual } from "node:util";
|
|
|
4
4
|
// OMP intentionally remaps only the package root to its callable tool schemas.
|
|
5
5
|
import { Type, type Static } from "@sinclair/typebox/type";
|
|
6
6
|
import { Value } from "@sinclair/typebox/value";
|
|
7
|
-
import type { Config } from "
|
|
8
|
-
import { authorizeRoute } from "
|
|
9
|
-
import type { InputRecord, OutputRecord, StorePort } from "
|
|
10
|
-
import { routeKey } from "
|
|
7
|
+
import type { Config } from "../config/config";
|
|
8
|
+
import { authorizeRoute } from "../config/config";
|
|
9
|
+
import type { InputRecord, OutputRecord, StorePort } from "../contracts";
|
|
10
|
+
import { routeKey } from "../contracts";
|
|
11
11
|
import { parsePrRef, prKey, readPrSnapshot, type PrSnapshot } from "./pr-github";
|
|
12
12
|
import { ciOutcomeSchema, PrReadError } from "./pr-github-schema";
|
|
13
13
|
|
|
@@ -92,7 +92,7 @@ function changes(watch: Watch, after: PrSnapshot): string[] {
|
|
|
92
92
|
|
|
93
93
|
/** HEAD-owned ordinary-code observation. Never sends a message or calls a lane. */
|
|
94
94
|
export class PrWatcher {
|
|
95
|
-
private running?: Promise<
|
|
95
|
+
private running?: Promise<boolean>;
|
|
96
96
|
|
|
97
97
|
constructor(
|
|
98
98
|
private readonly store: StorePort,
|
|
@@ -168,12 +168,17 @@ export class PrWatcher {
|
|
|
168
168
|
}
|
|
169
169
|
|
|
170
170
|
private source(id: string): InputRecord {
|
|
171
|
-
const source = this.
|
|
172
|
-
if (!source
|
|
171
|
+
const source = this.pollSource(id);
|
|
172
|
+
if (!source)
|
|
173
173
|
throw new PrWatchError("PR tracking requires an original authorized user source without a cancellation or uncertainty hold");
|
|
174
174
|
return source;
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
+
private pollSource(id: string): InputRecord | null {
|
|
178
|
+
const source = this.ownerSource(id);
|
|
179
|
+
return source && source.state !== "cancelled" && source.state !== "uncertain" ? source : null;
|
|
180
|
+
}
|
|
181
|
+
|
|
177
182
|
/** Recheck the exact registration at native submission, not just when the read completed. */
|
|
178
183
|
canConsume(input: InputRecord): boolean {
|
|
179
184
|
if (!isPrObservation(input.id)) return true;
|
|
@@ -182,9 +187,8 @@ export class PrWatcher {
|
|
|
182
187
|
const watch = state(this.store).watches.find(item => item.epoch === epoch);
|
|
183
188
|
if (!watch || watch.stopBoundary !== this.store.getMeta(STOP_BOUNDARY)
|
|
184
189
|
|| watch.sourceId !== this.store.getMeta(`activity-source:${input.id}`)) return false;
|
|
185
|
-
const source = this.
|
|
186
|
-
return
|
|
187
|
-
&& routeKey(input.route) === routeKey(source.route);
|
|
190
|
+
const source = this.pollSource(watch.sourceId);
|
|
191
|
+
return source !== null && routeKey(input.route) === routeKey(source.route);
|
|
188
192
|
}
|
|
189
193
|
|
|
190
194
|
deliverable(output: OutputRecord): boolean {
|
|
@@ -193,23 +197,27 @@ export class PrWatcher {
|
|
|
193
197
|
&& routeKey(output.route) === routeKey(input.route) && this.canConsume(input);
|
|
194
198
|
}
|
|
195
199
|
|
|
196
|
-
poll(now: number, signal: AbortSignal): Promise<
|
|
200
|
+
poll(now: number, signal: AbortSignal): Promise<boolean> {
|
|
197
201
|
if (this.running) return this.running;
|
|
198
202
|
this.running = this.observe(now, signal).finally(() => { this.running = undefined; });
|
|
199
203
|
return this.running;
|
|
200
204
|
}
|
|
201
205
|
|
|
202
|
-
private
|
|
206
|
+
private scheduled(watch: Watch, boundary: string | null): boolean {
|
|
207
|
+
return watch.snapshot?.state !== "merged" && watch.stopBoundary === boundary;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
hasScheduledWork(): boolean {
|
|
211
|
+
const boundary = this.store.getMeta(STOP_BOUNDARY);
|
|
212
|
+
return state(this.store).watches.some(watch => this.scheduled(watch, boundary) && this.pollSource(watch.sourceId) !== null);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
private async observe(now: number, signal: AbortSignal): Promise<boolean> {
|
|
216
|
+
let admitted = false;
|
|
203
217
|
for (const watch of state(this.store).watches) {
|
|
204
|
-
if (signal.aborted)
|
|
205
|
-
if (watch.nextCheckAt > now || watch.
|
|
206
|
-
|
|
207
|
-
let source: InputRecord;
|
|
208
|
-
try { source = this.source(watch.sourceId); }
|
|
209
|
-
catch (error) {
|
|
210
|
-
if (!(error instanceof PrWatchError)) throw error;
|
|
211
|
-
continue; // Cancelled/unauthorized sources never cause network reads or wakes.
|
|
212
|
-
}
|
|
218
|
+
if (signal.aborted) break;
|
|
219
|
+
if (watch.nextCheckAt > now || !this.scheduled(watch, this.store.getMeta(STOP_BOUNDARY))) continue;
|
|
220
|
+
if (!this.pollSource(watch.sourceId)) continue; // Cancelled/unauthorized sources never cause network reads or wakes.
|
|
213
221
|
let snapshot = watch.snapshot;
|
|
214
222
|
let baseline = watch.baseline ?? null;
|
|
215
223
|
let seen = watch.seen;
|
|
@@ -225,17 +233,17 @@ export class PrWatcher {
|
|
|
225
233
|
seen = [...new Set([...watch.seen, ...observed.feedback.map(item => item.key), ...observed.failures.map(item => item.key),
|
|
226
234
|
...("key" in observed.ci ? [observed.ci.key] : [])])];
|
|
227
235
|
} catch (failure) {
|
|
228
|
-
if (signal.aborted)
|
|
236
|
+
if (signal.aborted) break;
|
|
229
237
|
error = failure instanceof PrReadError || failure instanceof PrWatchError ? failure.message : "GitHub observation failed";
|
|
230
238
|
if (error !== watch.error) lines = ["PR_WATCH_ERROR: observation failed. No baseline was advanced. The owner can request tracking status in this conversation."];
|
|
231
239
|
}
|
|
232
|
-
if (signal.aborted)
|
|
240
|
+
if (signal.aborted) break;
|
|
233
241
|
// A user can untrack/rebind or stop the source while the read is in flight.
|
|
234
242
|
const current = state(this.store);
|
|
235
243
|
if (!current.watches.some(item => item.epoch === watch.epoch)
|
|
236
244
|
|| watch.stopBoundary !== this.store.getMeta(STOP_BOUNDARY)) continue;
|
|
237
|
-
|
|
238
|
-
|
|
245
|
+
const source = this.pollSource(watch.sourceId);
|
|
246
|
+
if (!source) continue;
|
|
239
247
|
const next = { ...watch, snapshot, baseline, seen, events: watch.events + (lines.length ? 1 : 0),
|
|
240
248
|
error, nextCheckAt: now + watch.intervalSeconds * 1000 };
|
|
241
249
|
const serialized = JSON.stringify({ ...current, watches: current.watches.map(item => item.epoch === watch.epoch ? next : item) });
|
|
@@ -243,7 +251,7 @@ export class PrWatcher {
|
|
|
243
251
|
const fingerprint = createHash("sha256").update(JSON.stringify([watch.epoch, next.events])).digest("hex");
|
|
244
252
|
const id = `${OBSERVATION_PREFIX}${fingerprint}`;
|
|
245
253
|
// Admission and the cursor are one existing Store transaction, not print-then-ACK.
|
|
246
|
-
this.store.receive({
|
|
254
|
+
const queued = this.store.receive({
|
|
247
255
|
id, route: source.route, messageId: source.messageId, receivedAt: source.receivedAt,
|
|
248
256
|
...(source.interactionId === undefined ? {} : { interactionId: source.interactionId }),
|
|
249
257
|
...(source.invocationId === undefined ? {} : { invocationId: source.invocationId }),
|
|
@@ -254,6 +262,8 @@ export class PrWatcher {
|
|
|
254
262
|
...lines,
|
|
255
263
|
].join("\n\n"), attachments: [],
|
|
256
264
|
}, "main", { [`activity-source:${id}`]: source.id, [`pr-observation:${id}`]: watch.epoch, [STATE_KEY]: serialized });
|
|
265
|
+
if (queued) admitted = true;
|
|
257
266
|
}
|
|
267
|
+
return admitted;
|
|
258
268
|
}
|
|
259
269
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type { Platform } from "
|
|
1
|
+
import type { Platform } from "../contracts";
|
|
2
2
|
|
|
3
3
|
/** Platform message order only; event/edit IDs and local arrival times are not clocks. */
|
|
4
4
|
export function compareMessageIds(platform: Platform, left: string, right: string): -1 | 0 | 1 | null {
|
|
5
|
-
|
|
5
|
+
// Kakao log IDs are numeric and increase within a chat.
|
|
6
|
+
if (platform === "discord" || platform === "telegram" || platform === "kakao") {
|
|
6
7
|
if (!/^\d+$/.test(left) || !/^\d+$/.test(right)) return null;
|
|
7
8
|
const a = BigInt(left);
|
|
8
9
|
const b = BigInt(right);
|
|
@@ -6,8 +6,8 @@ import { lstat, open, realpath } from "node:fs/promises";
|
|
|
6
6
|
import { dirname, isAbsolute, join, normalize } from "node:path";
|
|
7
7
|
import { resolveSessionLeafId, type SessionEntry } from "@oh-my-pi/pi-coding-agent/session/session-entries";
|
|
8
8
|
import { parseSessionContent } from "@oh-my-pi/pi-coding-agent/session/session-loader";
|
|
9
|
-
import type { Inbound, Lane } from "
|
|
10
|
-
import { parseLaneReportResult } from "
|
|
9
|
+
import type { Inbound, Lane } from "../contracts";
|
|
10
|
+
import { parseLaneReportResult } from "../lane/lane-report";
|
|
11
11
|
|
|
12
12
|
export interface TopicMatch {
|
|
13
13
|
readonly laneId: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { realpathSync, statSync } from "node:fs";
|
|
2
2
|
import { basename, isAbsolute } from "node:path";
|
|
3
|
-
import type { Lane } from "
|
|
3
|
+
import type { Lane } from "../contracts";
|
|
4
4
|
|
|
5
5
|
export const TOPIC_CHOICE_WAIT_MS = 5 * 60_000;
|
|
6
6
|
|
|
@@ -9,7 +9,9 @@ export function topicRequest(text: string) {
|
|
|
9
9
|
const request = text.replace(/^\s*\/new(?:\s+|$)/, "");
|
|
10
10
|
const header = /^cwd:[ \t]*([^\n]*)(?:\n|$)/i.exec(request.trimStart());
|
|
11
11
|
if (!header) return { text: request, cwd: null };
|
|
12
|
-
|
|
12
|
+
const path = header[1].trim();
|
|
13
|
+
const quoted = path.match(/^(["'])(\/.*)\1$/u);
|
|
14
|
+
return { text: request.trimStart().slice(header[0].length), cwd: quoted?.[2] ?? path };
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
/** Parse only the original Discord owner request body. An empty result asks for a task. */
|