omp-superagent 0.1.10 → 0.1.13
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 +71 -15
- package/README.ko.md +10 -1
- package/README.md +10 -1
- 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 +1 -0
- package/docs/OPERATIONS.en.md +282 -53
- package/docs/OPERATIONS.md +264 -45
- package/docs/design/execution.md +80 -52
- package/docs/design/messaging.md +113 -32
- package/docs/releases/0.1.11.md +20 -0
- package/docs/releases/0.1.13.md +13 -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 +13 -11
- package/scripts/{prepare-ulw.ts → prepare-super.ts} +1 -1
- package/scripts/upgrade-evidence-files.mjs +100 -0
- package/scripts/upgrade-evidence.mjs +192 -0
- package/scripts/upgrade-host-wire.mjs +162 -0
- package/skills/head/SKILL.md +12 -3
- package/skills/head/references/routing.md +1 -1
- package/skills/head/references/supervision.md +23 -26
- package/skills/lane/SKILL.md +28 -21
- package/skills/lane/references/workflow.md +15 -17
- package/src/cli.ts +33 -53
- package/src/{config.ts → config/config.ts} +7 -3
- package/src/config/wake-config.ts +36 -0
- package/src/contracts.ts +61 -12
- 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 +43 -25
- 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 +164 -36
- package/src/host-sdk-helper.ts +66 -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-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 +25 -7
- 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} +10 -2
- 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/{soul.ts → omp/soul.ts} +2 -2
- 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} +5 -5
- package/src/operator/stop-lane.ts +25 -0
- 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} +1 -1
- 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} +867 -1213
- 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} +75 -42
- 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/{lane-report.ts → lane/lane-report.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-reply-voice.ts → omp/host-reply-voice.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
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { DialogResponse, GatewayRestartNotice, GatewayRestartRecord, Inbound, Route } from "
|
|
2
|
-
import type { HeadRotation } from "
|
|
3
|
-
import type { ManagedUlwStatus } from "
|
|
4
|
-
import type { GroupRequest } from "
|
|
1
|
+
import type { DialogResponse, GatewayRestartNotice, GatewayRestartRecord, HistoryPlatform, Inbound, Route } from "../contracts";
|
|
2
|
+
import type { HeadRotation } from "../runtime/head-rotation";
|
|
3
|
+
import type { ManagedUlwStatus } from "../omp/managed-super";
|
|
4
|
+
import type { GroupRequest } from "../group/group-policy";
|
|
5
5
|
|
|
6
6
|
export type HeadInitialization = {
|
|
7
7
|
readonly sessionId: string;
|
|
@@ -30,20 +30,25 @@ export type GatewayStatus = {
|
|
|
30
30
|
readonly socketPath: string;
|
|
31
31
|
readonly error: string | null;
|
|
32
32
|
readonly initialization?: HeadInitialization;
|
|
33
|
-
readonly rotation?: Pick<HeadRotation, "id" | "
|
|
33
|
+
readonly rotation?: Pick<HeadRotation, "id" | "replacementSessionId"> & {
|
|
34
|
+
readonly stage: Exclude<HeadRotation["stage"], "sleeping">;
|
|
34
35
|
readonly previousSessionId: string;
|
|
35
36
|
};
|
|
37
|
+
readonly hibernation?: Pick<HeadRotation, "id" | "stage"> & {
|
|
38
|
+
readonly sessionId: string;
|
|
39
|
+
};
|
|
36
40
|
};
|
|
37
41
|
readonly ulw?: ManagedUlwStatus;
|
|
38
42
|
readonly restart?: Omit<GatewayRestartRecord, "sessionFile">;
|
|
39
43
|
};
|
|
40
44
|
|
|
41
45
|
export type GatewayEvent =
|
|
42
|
-
| { readonly kind: "message"; readonly input: Inbound }
|
|
46
|
+
| { readonly kind: "message"; readonly input: Inbound; readonly historyDeferred?: true }
|
|
43
47
|
| { readonly kind: "group"; readonly request: GroupRequest }
|
|
44
48
|
| { readonly kind: "answer"; readonly approvalId: string; readonly response: DialogResponse; readonly route: Route }
|
|
45
49
|
| ({ readonly kind: "restart" } & GatewayRestartNotice)
|
|
46
|
-
| { readonly kind: "reconnect"; readonly barrier?: string
|
|
50
|
+
| { readonly kind: "reconnect"; readonly barrier?: string; readonly historyRecovery?: true;
|
|
51
|
+
readonly historyPlatform?: HistoryPlatform; readonly historyBeforeUs?: number };
|
|
47
52
|
export type GatewayReceipt = "accepted" | "rejected" | "unresolved";
|
|
48
53
|
export type QueuedEvent = {
|
|
49
54
|
readonly sequence: number;
|
package/src/gateway-config.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// One-shot parser shared with the operator CLI. Return normalized config and
|
|
2
2
|
// its source digest; never load credential files, native OMP, or messenger SDKs.
|
|
3
|
-
import { loadConfigSnapshot } from "./config";
|
|
3
|
+
import { loadConfigSnapshot } from "./config/config";
|
|
4
4
|
|
|
5
5
|
const [file, ...extra] = process.argv.slice(2);
|
|
6
6
|
if (!file || extra.length) throw new Error("Expected one Gateway config file");
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// One shot, under the recorded restart-runner PID. Resolve FILE.env with the
|
|
2
2
|
// same private-file checks as `start`; never serialize tokens to argv or pipes.
|
|
3
3
|
import { resolve } from "node:path";
|
|
4
|
-
import { loadConfigSnapshot, requireMessengerCredentials } from "./config";
|
|
5
|
-
import { loadCredentials } from "./credentials";
|
|
6
|
-
import { requireGateway } from "./gateway-native";
|
|
4
|
+
import { loadConfigSnapshot, requireMessengerCredentials } from "./config/config";
|
|
5
|
+
import { loadCredentials } from "./config/credentials";
|
|
6
|
+
import { requireGateway } from "./gateway/gateway-native";
|
|
7
7
|
|
|
8
8
|
const [file, request, originalStateDir, ...extra] = process.argv.slice(2);
|
|
9
9
|
if (!file || !request || !originalStateDir || extra.length) throw new Error("Missing restart identity");
|
|
@@ -2,9 +2,9 @@ import { Database } from "bun:sqlite";
|
|
|
2
2
|
import { existsSync } from "node:fs";
|
|
3
3
|
import { isAbsolute, join } from "node:path";
|
|
4
4
|
import { isDeepStrictEqual } from "node:util";
|
|
5
|
-
import { isConfiguredRoute, type Config } from "
|
|
6
|
-
import type { Messenger } from "
|
|
7
|
-
import { DeliveryError } from "
|
|
5
|
+
import { isConfiguredRoute, type Config } from "../config/config";
|
|
6
|
+
import type { Messenger } from "../contracts";
|
|
7
|
+
import { DeliveryError } from "../messaging/delivery";
|
|
8
8
|
import { groupRoom, groupRoomKey, type GroupReply, type GroupRequest } from "./group-policy";
|
|
9
9
|
|
|
10
10
|
const schema = `
|
|
@@ -132,6 +132,11 @@ export class GroupAccess {
|
|
|
132
132
|
|
|
133
133
|
get busy(): boolean { return this.active !== undefined || this.sending !== undefined; }
|
|
134
134
|
get running(): boolean { return this.active !== undefined; }
|
|
135
|
+
get hasWork(): boolean {
|
|
136
|
+
return this.busy || this.db.query(`SELECT 1 WHERE
|
|
137
|
+
EXISTS (SELECT 1 FROM group_requests WHERE state IN ('pending','running')) OR
|
|
138
|
+
EXISTS (SELECT 1 FROM group_responses WHERE state IN ('ready','attempted','uncertain'))`).get() !== null;
|
|
139
|
+
}
|
|
135
140
|
|
|
136
141
|
private launch(report: (error: unknown) => void): void {
|
|
137
142
|
try {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { realpathSync, statSync } from "node:fs";
|
|
3
3
|
import { resolve } from "node:path";
|
|
4
|
-
import type { Config } from "
|
|
5
|
-
import type { Platform, Route } from "
|
|
4
|
+
import type { Config } from "../config/config";
|
|
5
|
+
import type { Platform, Route } from "../contracts";
|
|
6
6
|
|
|
7
7
|
export const GROUP_MODEL_SELECTOR = /^([a-z][a-z0-9-]{0,62})\/([a-zA-Z0-9][a-zA-Z0-9._/-]{0,158})$/;
|
|
8
8
|
|
|
@@ -5,7 +5,7 @@ import { lstat, mkdir, mkdtemp, open, realpath, rm, symlink, writeFile } from "n
|
|
|
5
5
|
import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
7
|
import { GROUP_MODEL_SELECTOR } from "./group-policy";
|
|
8
|
-
import { restrictedWorkTools } from "
|
|
8
|
+
import { restrictedWorkTools } from "../group-runner-extension";
|
|
9
9
|
|
|
10
10
|
type Input = {
|
|
11
11
|
readonly mode: "chat" | "work";
|
|
@@ -29,12 +29,12 @@ type Command = {
|
|
|
29
29
|
|
|
30
30
|
class RestrictedRunError extends Error {}
|
|
31
31
|
const safePath = "/usr/bin:/bin";
|
|
32
|
-
const extension = fileURLToPath(new URL("
|
|
32
|
+
const extension = fileURLToPath(new URL("../group-runner-extension.ts", import.meta.url));
|
|
33
33
|
const utf8 = new TextDecoder("utf-8", { fatal: true });
|
|
34
34
|
const checkoutBytes = 64 * 1024 * 1024;
|
|
35
35
|
const gitOid = /^(?:[a-f0-9]{40}|[a-f0-9]{64})$/;
|
|
36
36
|
const modelApis = new Set(["openai-completions", "openai-responses", "anthropic-messages", "google-generative-ai"]);
|
|
37
|
-
const isolationFlags = ["--no-session", "--no-
|
|
37
|
+
const isolationFlags = ["--no-session", "--no-extensions", "--no-context-files", "--no-rules",
|
|
38
38
|
"--no-skills", "--no-title", "--no-lsp", "--no-pty", "--no-prewalk", "--offline"] as const;
|
|
39
39
|
|
|
40
40
|
function command(argv: readonly [string, ...string[]], { cwd, env, signal, bytes, stdin }: Command): Promise<Buffer> {
|
|
@@ -248,7 +248,9 @@ export async function runRestrictedGroup(input: Input): Promise<Result> {
|
|
|
248
248
|
await writeFile(join(agent, "models.yml"), model, { mode: 0o600 });
|
|
249
249
|
await writeFile(join(agent, "config.yml"), JSON.stringify({
|
|
250
250
|
memory: { backend: "off" }, autolearn: { enabled: false }, mcp: { enableProjectConfig: false },
|
|
251
|
-
|
|
251
|
+
goal: { enabled: false }, compaction: { enabled: false }, advisor: { enabled: false },
|
|
252
|
+
dev: { autoqa: false }, magicKeywords: { enabled: false },
|
|
253
|
+
marketplace: { autoUpdate: "off" }, telemetry: { otlpExportEnabled: false },
|
|
252
254
|
}), { mode: 0o600 });
|
|
253
255
|
const env = { PATH: safePath, HOME: home, TMPDIR: sandbox, XDG_CONFIG_HOME: join(home, "config"),
|
|
254
256
|
XDG_DATA_HOME: join(home, "data"), XDG_STATE_HOME: join(home, "state"), XDG_CACHE_HOME: join(home, "cache"),
|
|
@@ -256,12 +258,15 @@ export async function runRestrictedGroup(input: Input): Promise<Result> {
|
|
|
256
258
|
const launch = { cwd, env, signal, bytes: 512 * 1024 };
|
|
257
259
|
const help = utf8.decode(await command([input.executable, "--help"], launch));
|
|
258
260
|
const required = [...isolationFlags, "--mode", "--model", "--thinking", "--max-time", "--max-cost", "--system-prompt",
|
|
259
|
-
...(input.mode === "work" ? ["--
|
|
261
|
+
...(input.mode === "work" ? ["--tools", "--approval-mode"] : ["--no-tools"])];
|
|
260
262
|
if (!required.every(flag => new RegExp(`(?:^|\\s)${flag}(?=[=,\\s])`, "m").test(help)))
|
|
261
263
|
return { ok: false };
|
|
262
264
|
if (input.mode === "work") worktree = await checkout(input, state, sandbox, signal);
|
|
265
|
+
// Stock --no-tools excludes extension factories. Group work instead loads
|
|
266
|
+
// only this allowlisted extension in the private profile and selects its tools.
|
|
263
267
|
const flags = worktree
|
|
264
|
-
? ["--extension", extension, "--tools", restrictedWorkTools.join(","), "--approval-mode", "yolo"]
|
|
268
|
+
? ["--trusted-extension", extension, "--tools", restrictedWorkTools.join(","), "--approval-mode", "yolo"]
|
|
269
|
+
: ["--no-tools"];
|
|
265
270
|
const output = await command([input.executable, "--mode", "json", ...isolationFlags,
|
|
266
271
|
"--model", input.model, "--thinking", "off", "--max-time", worktree ? "210s" : "45s", "--max-cost", worktree ? "0.25" : "0.05",
|
|
267
272
|
"--system-prompt", "The user message is a JSON string. Interpret its escapes literally. " + (worktree
|
package/src/host-extension.ts
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
import * as fs from "node:fs/promises";
|
|
2
2
|
import { realpathSync } from "node:fs";
|
|
3
3
|
import * as net from "node:net";
|
|
4
|
+
import { dirname } from "node:path";
|
|
4
5
|
import { fileURLToPath } from "node:url";
|
|
5
6
|
import { isDeepStrictEqual } from "node:util";
|
|
6
7
|
import type { ExtensionAPI, ExtensionContext } from "@oh-my-pi/pi-coding-agent";
|
|
7
8
|
import type { UnitScope } from "@oh-my-pi/pi-coding-agent/daemon/protocol";
|
|
8
|
-
import { cfgDefaultThinkingLevel } from "@oh-my-pi/pi-coding-agent/session/settings";
|
|
9
|
+
import { cfgDefaultThinkingLevel, cfgTierAnthropic, cfgTierGoogle, cfgTierOpenai } from "@oh-my-pi/pi-coding-agent/session/settings";
|
|
9
10
|
import { Settings } from "@oh-my-pi/pi-coding-agent/config/settings";
|
|
10
11
|
import { lookup as lookupSetting } from "@oh-my-pi/pi-coding-agent/config/registry";
|
|
11
|
-
import { formatModelStringWithRouting, pickDefaultAvailableModel, resolveModelRoleValue
|
|
12
|
-
|
|
12
|
+
import { formatModelStringWithRouting, pickDefaultAvailableModel, resolveModelRoleValue,
|
|
13
|
+
resolveSessionModelSelector } from "@oh-my-pi/pi-coding-agent/config/model-resolver";
|
|
14
|
+
import { buildServiceTierByFamily } from "@oh-my-pi/pi-coding-agent/config/service-tier";
|
|
15
|
+
import { getRestorableSessionModels } from "@oh-my-pi/pi-coding-agent/session/session-context";
|
|
16
|
+
import { clampThinkingLevelForModel } from "@oh-my-pi/pi-catalog/model-thinking";
|
|
13
17
|
import { parseSessionEntries, readSessionHeaderId } from "@oh-my-pi/pi-coding-agent/session/session-loader";
|
|
14
|
-
import { HostChannel, LANE_MODEL_PROMOTION_RECEIPT, PR_REVIEW_GITHUB_ENV, PR_REVIEW_SYSTEM_PROMPT, indexServiceCompletions, serviceGenerationKey, type Frame, type ServiceUnit } from "./host-protocol";
|
|
18
|
+
import { HostChannel, LANE_MODEL_PROMOTION_RECEIPT, PR_REVIEW_GITHUB_ENV, PR_REVIEW_SYSTEM_PROMPT, indexServiceCompletions, serviceGenerationKey, type FastModeState, type Frame, type ServiceUnit } from "./omp/host-protocol";
|
|
15
19
|
import { USER_INTERRUPT_LABEL } from "@oh-my-pi/pi-coding-agent/session/messages";
|
|
16
20
|
import { MAX_RPC_REASSEMBLED_BYTES } from "@oh-my-pi/pi-coding-agent/modes/rpc/rpc-frame";
|
|
17
21
|
import { fitAbortAndRestoreQueueResponse } from "@oh-my-pi/pi-coding-agent/modes/rpc/rpc-mode";
|
|
@@ -19,12 +23,15 @@ import type { RpcAbortAndRestoreQueueResult, RpcSessionState } from "@oh-my-pi/p
|
|
|
19
23
|
import { calculateTokensPerSecond } from "@oh-my-pi/pi-coding-agent/utils/token-rate";
|
|
20
24
|
import { toolWireSchema } from "@oh-my-pi/pi-ai/utils/schema";
|
|
21
25
|
import type { LanePresetSnapshot } from "./contracts";
|
|
22
|
-
import { MANAGED_ULW_ENV } from "./managed-
|
|
23
|
-
import { verifyHostSuperkit } from "./host-superkit";
|
|
24
|
-
import { isPrReviewInferenceModel, prReviewModelChoices } from "./pr-review-models";
|
|
25
|
-
import { HEAD_ROTATION_GUARD, HEAD_ROTATION_PROBE, type
|
|
26
|
-
type RotationNative, type RotationProbeEvent } from "./head-rotation";
|
|
27
|
-
import { installReplyVoice } from "./host-reply-voice";
|
|
26
|
+
import { MANAGED_ULW_ENV } from "./omp/managed-super";
|
|
27
|
+
import { verifyHostSuperkit } from "./omp/host-superkit";
|
|
28
|
+
import { isPrReviewInferenceModel, prReviewModelChoices } from "./pr/pr-review-models";
|
|
29
|
+
import { HEAD_ROTATION_GUARD, HEAD_ROTATION_PROBE, HEAD_SLEEP_PROBE_READY, type HeadLifecycleMode,
|
|
30
|
+
type HeadSleepProbeReadyEvent, type RotationGuardEvent, type RotationNative, type RotationProbeEvent } from "./runtime/head-rotation";
|
|
31
|
+
import { installReplyVoice } from "./omp/host-reply-voice";
|
|
32
|
+
import { matchesPreparedLaunch } from "./omp/stock-head-launch";
|
|
33
|
+
import { NATIVE_PROFILE_ENV, bindNativeProfile, matchesNativeProfile, type HostReadyEvent,
|
|
34
|
+
type NativeProfileBinding, type NativeProfilePaths } from "./omp/native-sessions";
|
|
28
35
|
|
|
29
36
|
const terminalService = (state: ServiceUnit["state"]) => state === "exited" || state === "failed";
|
|
30
37
|
const serviceGeneration = ({ owner, id, generation, startedAt, restartCount }: ServiceUnit) =>
|
|
@@ -36,12 +43,12 @@ const serviceOwner = ({ agent, sessionManager }: ExtensionContext) => {
|
|
|
36
43
|
};
|
|
37
44
|
|
|
38
45
|
const stockAutoresearchTools = ["init_experiment", "run_experiment", "log_experiment", "update_notes"] as const;
|
|
39
|
-
//
|
|
40
|
-
//
|
|
41
|
-
|
|
42
|
-
const stockInactiveTools = new Set(["write", "resolve", "reject", "propose", "report_issue"]);
|
|
46
|
+
// An empty built-in selection can still leave native registrations: write on
|
|
47
|
+
// stock 19.0 and resolution devices on 19.1+. They must never be executable.
|
|
48
|
+
const stockInactiveTools = new Set(["write", "resolve", "reject", "propose"]);
|
|
43
49
|
const reviewSettingValues = {
|
|
44
|
-
"memory.backend": "off", "goal.enabled": false, "
|
|
50
|
+
"memory.backend": "off", "goal.enabled": false, "plan.enabled": false, "compaction.enabled": false,
|
|
51
|
+
"advisor.enabled": false, "autolearn.enabled": false, "speechgen.enabled": false, externalThinking: false,
|
|
45
52
|
"skills.enabled": false, "skills.enableSkillCommands": false, "mcp.enableProjectConfig": false,
|
|
46
53
|
"marketplace.autoUpdate": "off", "magicKeywords.enabled": false, "prewalk.enabled": false,
|
|
47
54
|
"prewalk.auto": "off", "spotlight.experiment.enabled": false, "providers.cacheWarming": "off", "telemetry.otlpExportEnabled": false,
|
|
@@ -88,6 +95,9 @@ export default function hostExtension(pi: ExtensionAPI): void {
|
|
|
88
95
|
if (reviewCwd && PR_REVIEW_GITHUB_ENV.some(name => process.env[name]))
|
|
89
96
|
throw new Error("Static PR review cannot load GitHub credentials from the native profile");
|
|
90
97
|
let loadedSuperkitPath: string | undefined;
|
|
98
|
+
let stockLaunchReplay: true | undefined;
|
|
99
|
+
const profileBinding: NativeProfileBinding | null = JSON.parse(process.env[NATIVE_PROFILE_ENV] ?? "null");
|
|
100
|
+
let nativeProfilePaths: NativeProfilePaths | undefined;
|
|
91
101
|
type ServiceStart = {
|
|
92
102
|
readonly name: string; readonly scope: UnitScope; readonly owner: string;
|
|
93
103
|
readonly sessionId: string; readonly toolCallId: string;
|
|
@@ -181,6 +191,17 @@ export default function hostExtension(pi: ExtensionAPI): void {
|
|
|
181
191
|
hostPid: process.pid, sessionId: id, sessionFile: file, generation: ref.generation, instanceKey: session.instanceKey,
|
|
182
192
|
...(workerAttempt ? { workerAttempt, workerCwd: context?.cwd } : {}),
|
|
183
193
|
});
|
|
194
|
+
const currentNativeProfile = (file: string | undefined) => {
|
|
195
|
+
if (!profileBinding || !nativeProfilePaths || !file) return;
|
|
196
|
+
const { profile, discoveryEntry } = profileBinding;
|
|
197
|
+
try {
|
|
198
|
+
if (matchesNativeProfile(nativeProfilePaths, profile) && realpathSync(dirname(discoveryEntry)) === dirname(discoveryEntry)
|
|
199
|
+
&& realpathSync(discoveryEntry) === realpathSync(file)) return profile;
|
|
200
|
+
} catch (error) {
|
|
201
|
+
// An unavailable filesystem cannot prove a profile for shutdown or wake.
|
|
202
|
+
if (!(error instanceof Error)) throw error;
|
|
203
|
+
}
|
|
204
|
+
};
|
|
184
205
|
const snapshot = () => {
|
|
185
206
|
const { session } = exact();
|
|
186
207
|
return { modelRoles: session.settings.getModelRoles(),
|
|
@@ -207,7 +228,8 @@ export default function hostExtension(pi: ExtensionAPI): void {
|
|
|
207
228
|
if (!Array.isArray(mounted) || mounted.length)
|
|
208
229
|
throw new ReviewIsolationError("Static PR review cannot establish an empty native device tool set");
|
|
209
230
|
if (!Array.isArray(session.agent.state.tools) || session.agent.state.tools.length ||
|
|
210
|
-
!Array.isArray(session.skills) || session.skills.length || session.autoCompactionEnabled !== false ||
|
|
231
|
+
!Array.isArray(session.skills) || session.skills.length || session.autoCompactionEnabled !== false ||
|
|
232
|
+
session.getGoalModeState()?.enabled || session.getPlanModeState()?.enabled)
|
|
211
233
|
throw new ReviewIsolationError("Static PR review found native tools, skills, or autonomous execution enabled");
|
|
212
234
|
return { version: 1, cwd, modelApi: model.api };
|
|
213
235
|
};
|
|
@@ -221,7 +243,7 @@ export default function hostExtension(pi: ExtensionAPI): void {
|
|
|
221
243
|
const extensions = runner.getLoadedExtensions();
|
|
222
244
|
const other = extensions.filter(extension => extension.resolvedPath !== self);
|
|
223
245
|
// Stock SDKs may register their internal autoresearch factory and its
|
|
224
|
-
// default-inactive tools even with
|
|
246
|
+
// default-inactive tools even with an empty selection. No ambient extension or
|
|
225
247
|
// arbitrary inline factory may be active in a review session.
|
|
226
248
|
if (!extensions.some(extension => extension.resolvedPath === self && runner.isExtensionActive(extension.path))
|
|
227
249
|
|| other.some(extension => !/^<inline-\d+>$/.test(extension.resolvedPath)
|
|
@@ -467,8 +489,9 @@ export default function hostExtension(pi: ExtensionAPI): void {
|
|
|
467
489
|
[ref.id, ref.generation, ref.parentId, ref.session?.instanceKey, ref.sessionFile])))
|
|
468
490
|
throw new DescendantOwnershipChanged("Native descendant identity changed during completion readback");
|
|
469
491
|
const tree = identity.session.getAsyncJobTree({ recentLimit: 0 });
|
|
470
|
-
|
|
471
|
-
|
|
492
|
+
const otherWork = liveGenerations.size > 0 || descendantsBusy() || deliveriesPending(identity.session);
|
|
493
|
+
return { identity, tree, otherWork, unknown: servicesUnknown || serviceDeliveryUnknown || descendantsUnknown(),
|
|
494
|
+
busy: otherWork || !!tree?.running.length };
|
|
472
495
|
};
|
|
473
496
|
const owned = async (drain = false) => {
|
|
474
497
|
const identity = exact();
|
|
@@ -492,21 +515,57 @@ export default function hostExtension(pi: ExtensionAPI): void {
|
|
|
492
515
|
&& !session.yieldQueue.has()
|
|
493
516
|
&& !session.getGoalModeState()?.enabled;
|
|
494
517
|
};
|
|
495
|
-
const
|
|
496
|
-
if (process.env.OMP_SUPERAGENT_ROLE !== "head" ||
|
|
518
|
+
const headFastMode = (session: NativeSession): FastModeState | undefined => {
|
|
519
|
+
if (process.env.OMP_SUPERAGENT_ROLE !== "head" || typeof session.setFastMode !== "function"
|
|
520
|
+
|| typeof session.setUltrafastMode !== "function" || typeof session.isUltrafastModeEnabled !== "function") return;
|
|
521
|
+
return {
|
|
522
|
+
mode: session.isUltrafastModeEnabled() ? "ultra" : session.isFastModeEnabled() ? "on" : "off",
|
|
523
|
+
active: session.isFastModeActive(),
|
|
524
|
+
};
|
|
525
|
+
};
|
|
526
|
+
const rotationState = (mode: HeadLifecycleMode | undefined): RotationNative | null => {
|
|
527
|
+
if (process.env.OMP_SUPERAGENT_ROLE !== "head" || !stockLaunchReplay || !localIdle()) return null;
|
|
497
528
|
const { id, file, session } = exact();
|
|
529
|
+
const hibernation = mode === "hibernate" ? currentNativeProfile(file) : undefined;
|
|
530
|
+
if (mode === "hibernate") {
|
|
531
|
+
const goal = session.getGoalModeState()?.goal;
|
|
532
|
+
// A paused/budget-limited goal, an open plan or an armed native
|
|
533
|
+
// prewalk is still owned work.
|
|
534
|
+
if (!hibernation || (goal && goal.status !== "complete" && goal.status !== "dropped")
|
|
535
|
+
|| session.getPlanModeState()?.enabled || session.getPrewalkState?.())
|
|
536
|
+
return null;
|
|
537
|
+
}
|
|
498
538
|
const usage = session.getContextUsage();
|
|
539
|
+
const contextPercent = usage && typeof usage.tokens === "number" && Number.isFinite(usage.tokens)
|
|
540
|
+
&& typeof usage.percent === "number" && Number.isFinite(usage.percent) && usage.percent >= 0
|
|
541
|
+
&& Number.isFinite(usage.contextWindow) && usage.contextWindow > 0 ? usage.percent : null;
|
|
499
542
|
const model = session.model;
|
|
500
|
-
if (!file ||
|
|
501
|
-
|| typeof usage.percent !== "number" || !Number.isFinite(usage.percent) || usage.percent < 50
|
|
502
|
-
|| !Number.isFinite(usage.contextWindow) || usage.contextWindow <= 0
|
|
543
|
+
if (!file || mode === undefined && (contextPercent === null || contextPercent < 50)
|
|
503
544
|
|| !model || typeof model.reasoning !== "boolean" || typeof session.configuredThinkingLevel !== "function") return null;
|
|
504
545
|
const { modelRoles, defaultThinkingLevel } = snapshot();
|
|
505
546
|
const roles = Object.fromEntries(Object.entries(modelRoles).filter((entry): entry is [string, string] =>
|
|
506
547
|
typeof entry[1] === "string"));
|
|
548
|
+
const modelIdentity = formatModelStringWithRouting(model);
|
|
549
|
+
let tierSelection: Pick<RotationNative["selection"], "serviceTier" | "serviceTierDefaults" | "effectiveServiceTier"> | undefined;
|
|
550
|
+
if (mode === "hibernate") {
|
|
551
|
+
if (!session.serviceTierByFamily || typeof session.effectiveServiceTier !== "function") return null;
|
|
552
|
+
const settings = readOnly(session.settings);
|
|
553
|
+
tierSelection = {
|
|
554
|
+
serviceTier: { ...session.serviceTierByFamily }, effectiveServiceTier: session.effectiveServiceTier(model) ?? "none",
|
|
555
|
+
serviceTierDefaults: buildServiceTierByFamily(cfgTierOpenai.get(settings), cfgTierAnthropic.get(settings), cfgTierGoogle.get(settings)),
|
|
556
|
+
};
|
|
557
|
+
const manager = session.sessionManager;
|
|
558
|
+
const selectors = getRestorableSessionModels(manager.buildSessionContext().models, manager.getLastModelChangeRole());
|
|
559
|
+
const selector = selectors[0] ?? roles.default;
|
|
560
|
+
const resolved = selector && resolveSessionModelSelector(session.modelRegistry, selector)?.model;
|
|
561
|
+
// A selector ending in @upstream can instead be a literal catalog ID.
|
|
562
|
+
if (!resolved || resolved.id !== model.id || formatModelStringWithRouting(resolved) !== modelIdentity) return null;
|
|
563
|
+
}
|
|
507
564
|
return { hostPid: process.pid, sessionId: id, sessionFile: file, nativeRun: runOrdinal,
|
|
508
|
-
contextPercent
|
|
509
|
-
|
|
565
|
+
contextPercent,
|
|
566
|
+
...(hibernation ? { hibernation } : {}),
|
|
567
|
+
selection: { provider: model.provider, modelId: model.id, modelIdentity, reasoning: model.reasoning,
|
|
568
|
+
stockLaunchReplay, ...tierSelection,
|
|
510
569
|
thinkingLevel: session.thinkingLevel ?? null, configuredThinkingLevel: session.configuredThinkingLevel() ?? null,
|
|
511
570
|
modelSettings: { modelRoles: roles, ...(defaultThinkingLevel !== undefined ? { defaultThinkingLevel } : {}) } } };
|
|
512
571
|
};
|
|
@@ -520,10 +579,18 @@ export default function hostExtension(pi: ExtensionAPI): void {
|
|
|
520
579
|
return {};
|
|
521
580
|
}
|
|
522
581
|
if (command.type === "get_head_rotation") {
|
|
523
|
-
const
|
|
582
|
+
const { mode } = command;
|
|
583
|
+
if (mode !== undefined && mode !== "hibernate") throw new Error("Unsupported HEAD lifecycle mode");
|
|
584
|
+
if (mode === "hibernate") {
|
|
585
|
+
if (process.env.OMP_SUPERAGENT_ROLE !== "head") return null;
|
|
586
|
+
let ready = false;
|
|
587
|
+
pi.events.emit(HEAD_SLEEP_PROBE_READY, { respond: value => { ready = value; } } satisfies HeadSleepProbeReadyEvent);
|
|
588
|
+
if (!ready) return null;
|
|
589
|
+
}
|
|
590
|
+
const state = rotationState(mode);
|
|
524
591
|
if (!state) return null;
|
|
525
592
|
let attestation: Parameters<RotationProbeEvent["respond"]>[0] | undefined;
|
|
526
|
-
pi.events.emit(HEAD_ROTATION_PROBE, { state, respond: value => { attestation = value; } } satisfies RotationProbeEvent);
|
|
593
|
+
pi.events.emit(HEAD_ROTATION_PROBE, { mode, state, respond: value => { attestation = value; } } satisfies RotationProbeEvent);
|
|
527
594
|
return attestation ?? null;
|
|
528
595
|
}
|
|
529
596
|
if (command.type === "get_session_stats") return exact().session.getSessionStats();
|
|
@@ -583,9 +650,15 @@ export default function hostExtension(pi: ExtensionAPI): void {
|
|
|
583
650
|
}
|
|
584
651
|
if (command.type === "activate") {
|
|
585
652
|
const identity = exact();
|
|
653
|
+
if (process.env.OMP_SUPERAGENT_ROLE === "head" && matchesPreparedLaunch(
|
|
654
|
+
process.argv.slice(2), command.replayableArgvHash, identity.session.extensionRunner?.getFlags?.(),
|
|
655
|
+
)) stockLaunchReplay = true;
|
|
656
|
+
const nativeProfile = currentNativeProfile(identity.file);
|
|
657
|
+
if (!identity.file || ((profileBinding || command.waking === true) && !nativeProfile))
|
|
658
|
+
throw new Error("Native Host profile changed before activation");
|
|
586
659
|
if (reviewCwd) {
|
|
587
|
-
if (command.
|
|
588
|
-
throw new Error("Static PR review requires
|
|
660
|
+
if (command.emptyToolSelection !== true || command.noTools !== false || command.toolsExplicitlySelected !== true)
|
|
661
|
+
throw new Error("Static PR review requires an explicit empty native tool selection");
|
|
589
662
|
reviewPolicy(identity.session, reviewCwd);
|
|
590
663
|
}
|
|
591
664
|
// Native's default tool selection omits the goal tool. Add it only for
|
|
@@ -593,7 +666,9 @@ export default function hostExtension(pi: ExtensionAPI): void {
|
|
|
593
666
|
if (command.toolsExplicitlySelected === false && command.noTools === false
|
|
594
667
|
&& goalEnabled.get(readOnly(identity.session.settings)) === true)
|
|
595
668
|
await pi.setActiveTools([...new Set([...pi.getActiveTools(), "goal"])]);
|
|
596
|
-
|
|
669
|
+
if (nativeProfile && !currentNativeProfile(identity.file)) throw new Error("Native Host profile changed before activation");
|
|
670
|
+
pi.events.emit("superagent:host-ready", { sessionId: identity.id, sessionFile: identity.file, pid: process.pid,
|
|
671
|
+
...(nativeProfile ? { nativeProfile } : {}), ...(command.waking === true ? { waking: true } : {}) } satisfies HostReadyEvent);
|
|
597
672
|
return {};
|
|
598
673
|
}
|
|
599
674
|
if (command.type === "observe") {
|
|
@@ -612,16 +687,56 @@ export default function hostExtension(pi: ExtensionAPI): void {
|
|
|
612
687
|
// The owner requires this first snapshot before opening its public socket.
|
|
613
688
|
const prReviewPolicy = reviewCwd ? reviewPolicy(ownership.identity.session, reviewCwd) : undefined;
|
|
614
689
|
if (!reviewCwd) loadedSuperkitPath ??= await verifyHostSuperkit(ownership.identity.session, selectedSuperkit);
|
|
690
|
+
const { session, ref } = ownership.identity;
|
|
691
|
+
const wakes = session.wakeSources;
|
|
692
|
+
const running = process.env.OMP_SUPERAGENT_ROLE === "head" && ownership.tree
|
|
693
|
+
? ownership.tree.running.filter(job => job.ownerId === ref.id) : undefined;
|
|
694
|
+
const awaitingOnly = !ownership.unknown && !ownership.otherWork && !!running && !!wakes?.jobs.length
|
|
695
|
+
&& wakes.agents.length === 0 && !wakes.queued && running.length === ownership.tree?.running.length
|
|
696
|
+
&& running.length === wakes.jobs.length && wakes.jobs.every(id => running.some(job => job.id === id))
|
|
697
|
+
&& session.isRunActive === true && !session.isDisposed && !session.isBusyForSnapshot && !session.isSessionTransitioning
|
|
698
|
+
&& !session.hasAdmittedSubmission && !session.hasPostPromptWork && session.queuedMessageCount === 0
|
|
699
|
+
&& !session.yieldQueue.has() && !session.getGoalModeState()?.enabled && !mutationHeld && !observationHeld;
|
|
615
700
|
// Only an owner that implements the cursor command can advertise it to peers.
|
|
616
701
|
return { ...ownerIdentity(ownership.identity), loadedSuperkitPath, prReviewPolicy, settingsScope: "session", modelSettings: snapshot(),
|
|
702
|
+
nativeProfile: currentNativeProfile(ownership.identity.file),
|
|
703
|
+
...(process.env.OMP_SUPERAGENT_ROLE === "head" ? {
|
|
704
|
+
stockLaunchReplay,
|
|
705
|
+
modelIdentity: session.model && formatModelStringWithRouting(session.model),
|
|
706
|
+
serviceTier: session.serviceTierByFamily,
|
|
707
|
+
effectiveServiceTier: session.model && typeof session.effectiveServiceTier === "function"
|
|
708
|
+
? session.effectiveServiceTier(session.model) ?? "none" : undefined,
|
|
709
|
+
} : {}),
|
|
617
710
|
journalCursorControlVersion: 1,
|
|
618
711
|
...(replyVoice?.available() ? { replyVoiceControlVersion: 2 } : {}),
|
|
712
|
+
...(running ? { headJobs: { running: running.map(job => job.id), awaitingOnly } } : {}),
|
|
713
|
+
fastMode: headFastMode(ownership.identity.session),
|
|
619
714
|
hasOwnedRunningWork: ownership.unknown ? undefined : ownership.busy, mutationHeld, observationHeld,
|
|
620
715
|
admitted: ownership.identity.session.hasAdmittedSubmission,
|
|
621
716
|
postPromptWork: ownership.identity.session.hasPostPromptWork,
|
|
622
717
|
...(typeof ownership.identity.session.configuredThinkingLevel === "function"
|
|
623
718
|
? { configuredThinkingLevel: ownership.identity.session.configuredThinkingLevel() ?? null } : {}) };
|
|
624
719
|
}
|
|
720
|
+
if (command.type === "set_head_fast_mode") {
|
|
721
|
+
const { mode } = command;
|
|
722
|
+
if (mode !== "on" && mode !== "ultra" && mode !== "off") throw new Error("Invalid fast mode");
|
|
723
|
+
if (!localIdle()) throw new Error("session_busy");
|
|
724
|
+
const ownership = await owned(true);
|
|
725
|
+
const { session, ref } = ownership.identity;
|
|
726
|
+
if (ownership.unknown || ownership.busy || exact().ref !== ref || !localIdle()) throw new Error("session_busy");
|
|
727
|
+
if (!headFastMode(session) || !session.model || session.model.provider !== command.provider
|
|
728
|
+
|| session.model.id !== command.modelId) return { result: "unavailable" };
|
|
729
|
+
mutationHeld = true;
|
|
730
|
+
const applied = mode === "ultra" ? session.setUltrafastMode(true) : session.setFastMode(mode === "on");
|
|
731
|
+
if (!applied) {
|
|
732
|
+
mutationHeld = false;
|
|
733
|
+
return { result: "unsupported" };
|
|
734
|
+
}
|
|
735
|
+
if (headFastMode(session)?.mode !== mode) throw new Error("Native fast tier readback differs");
|
|
736
|
+
session.sessionManager.flushSync();
|
|
737
|
+
mutationHeld = false;
|
|
738
|
+
return { result: "applied" };
|
|
739
|
+
}
|
|
625
740
|
if (command.type === "set_lane_model") {
|
|
626
741
|
if (reviewCwd || process.env.OMP_SUPERAGENT_ROLE !== "lane")
|
|
627
742
|
throw new Error("An ordinary managed lane Host is required");
|
|
@@ -710,8 +825,8 @@ export default function hostExtension(pi: ExtensionAPI): void {
|
|
|
710
825
|
if (!model) throw new Error("Native model resolution failed; mutation remains held");
|
|
711
826
|
const expectedLevel = "thinkingLevel" in selected && selected.thinkingLevel !== undefined
|
|
712
827
|
? selected.thinkingLevel : preset.defaultThinkingLevel;
|
|
713
|
-
const effectiveLevel = expectedLevel === "auto"
|
|
714
|
-
: expectedLevel ===
|
|
828
|
+
const effectiveLevel = expectedLevel === "auto" || expectedLevel === "off" ? expectedLevel
|
|
829
|
+
: expectedLevel === "inherit" ? undefined : clampThinkingLevelForModel(model, expectedLevel);
|
|
715
830
|
if (!command.preserveActiveModel) {
|
|
716
831
|
await ownership.identity.session.setModelTemporary(model, expectedLevel);
|
|
717
832
|
}
|
|
@@ -724,6 +839,10 @@ export default function hostExtension(pi: ExtensionAPI): void {
|
|
|
724
839
|
return { name: command.name, settingsScope: "session", preset: snapshot(), model: ownership.identity.session.model };
|
|
725
840
|
}
|
|
726
841
|
if (command.type === "shutdown_host") {
|
|
842
|
+
const { mode, headRotation } = command;
|
|
843
|
+
if (mode !== undefined && mode !== "hibernate") throw new Error("Unsupported HEAD lifecycle mode");
|
|
844
|
+
if (mode === "hibernate" && typeof headRotation !== "string")
|
|
845
|
+
throw new Error("Invalid guarded HEAD shutdown");
|
|
727
846
|
if (!localIdle()) throw new Error("session_busy");
|
|
728
847
|
const ownership = await owned(true);
|
|
729
848
|
await ownership.identity.session.waitForIdle();
|
|
@@ -731,11 +850,11 @@ export default function hostExtension(pi: ExtensionAPI): void {
|
|
|
731
850
|
const finalOwnership = await owned(true);
|
|
732
851
|
if (exact().ref !== ownership.identity.ref || !localIdle() || ownership.unknown || finalOwnership.unknown
|
|
733
852
|
|| ownership.busy || finalOwnership.busy) throw new Error("session_busy");
|
|
734
|
-
if (typeof
|
|
735
|
-
const state = rotationState();
|
|
853
|
+
if (typeof headRotation === "string") {
|
|
854
|
+
const state = rotationState(mode);
|
|
736
855
|
if (!state) throw new Error("session_busy");
|
|
737
856
|
let allowed = false;
|
|
738
|
-
pi.events.emit(HEAD_ROTATION_GUARD, { id:
|
|
857
|
+
pi.events.emit(HEAD_ROTATION_GUARD, { id: headRotation, mode, state,
|
|
739
858
|
respond: value => { allowed = value; } } satisfies RotationGuardEvent);
|
|
740
859
|
if (!allowed) throw new Error("session_busy");
|
|
741
860
|
}
|
|
@@ -843,6 +962,15 @@ export default function hostExtension(pi: ExtensionAPI): void {
|
|
|
843
962
|
context = ctx;
|
|
844
963
|
const identity = exact();
|
|
845
964
|
pendingNativeWake(identity.session);
|
|
965
|
+
// Check the actual stock session before materializing or appending to its journal.
|
|
966
|
+
if (profileBinding) {
|
|
967
|
+
if (!identity.file) throw new Error("Native Host did not open its prepared journal");
|
|
968
|
+
nativeProfilePaths = await bindNativeProfile(pi.pi, {
|
|
969
|
+
agentDir: identity.session.settings.getAgentDir(), file: identity.file, id: identity.id,
|
|
970
|
+
}, profileBinding);
|
|
971
|
+
if (exact().ref !== identity.ref || !currentNativeProfile(identity.file))
|
|
972
|
+
throw new Error("Native Host profile changed before journal materialization");
|
|
973
|
+
}
|
|
846
974
|
if (reviewCwd) {
|
|
847
975
|
try { await armReview(identity.session, reviewCwd); }
|
|
848
976
|
catch (error) {
|