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
|
@@ -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,11 +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";
|
|
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";
|
|
27
35
|
|
|
28
36
|
const terminalService = (state: ServiceUnit["state"]) => state === "exited" || state === "failed";
|
|
29
37
|
const serviceGeneration = ({ owner, id, generation, startedAt, restartCount }: ServiceUnit) =>
|
|
@@ -35,18 +43,19 @@ const serviceOwner = ({ agent, sessionManager }: ExtensionContext) => {
|
|
|
35
43
|
};
|
|
36
44
|
|
|
37
45
|
const stockAutoresearchTools = ["init_experiment", "run_experiment", "log_experiment", "update_notes"] as const;
|
|
38
|
-
//
|
|
39
|
-
//
|
|
40
|
-
|
|
41
|
-
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"]);
|
|
42
49
|
const reviewSettingValues = {
|
|
43
|
-
"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,
|
|
44
52
|
"skills.enabled": false, "skills.enableSkillCommands": false, "mcp.enableProjectConfig": false,
|
|
45
53
|
"marketplace.autoUpdate": "off", "magicKeywords.enabled": false, "prewalk.enabled": false,
|
|
46
54
|
"prewalk.auto": "off", "spotlight.experiment.enabled": false, "providers.cacheWarming": "off", "telemetry.otlpExportEnabled": false,
|
|
47
55
|
"dev.autoqa": false,
|
|
48
56
|
} as const;
|
|
49
57
|
class ReviewIsolationError extends Error {}
|
|
58
|
+
class DescendantOwnershipChanged extends Error {}
|
|
50
59
|
|
|
51
60
|
/** Match the running CLI's own RPC settlement predicate (old and new SDK surface). */
|
|
52
61
|
function pendingNativeWake(session: { readonly wakeSources?: unknown; readonly hasPendingAsyncWork?: () => boolean }): boolean {
|
|
@@ -82,9 +91,13 @@ export default function hostExtension(pi: ExtensionAPI): void {
|
|
|
82
91
|
const selectedSuperkit = process.env[MANAGED_ULW_ENV];
|
|
83
92
|
const workerAttempt = process.env.OMP_SUPERAGENT_WORKER_ATTEMPT;
|
|
84
93
|
const reviewCwd = process.env.OMP_SUPERAGENT_PR_REVIEW_CWD;
|
|
94
|
+
let replyVoice: ReturnType<typeof installReplyVoice>;
|
|
85
95
|
if (reviewCwd && PR_REVIEW_GITHUB_ENV.some(name => process.env[name]))
|
|
86
96
|
throw new Error("Static PR review cannot load GitHub credentials from the native profile");
|
|
87
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;
|
|
88
101
|
type ServiceStart = {
|
|
89
102
|
readonly name: string; readonly scope: UnitScope; readonly owner: string;
|
|
90
103
|
readonly sessionId: string; readonly toolCallId: string;
|
|
@@ -178,6 +191,17 @@ export default function hostExtension(pi: ExtensionAPI): void {
|
|
|
178
191
|
hostPid: process.pid, sessionId: id, sessionFile: file, generation: ref.generation, instanceKey: session.instanceKey,
|
|
179
192
|
...(workerAttempt ? { workerAttempt, workerCwd: context?.cwd } : {}),
|
|
180
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
|
+
};
|
|
181
205
|
const snapshot = () => {
|
|
182
206
|
const { session } = exact();
|
|
183
207
|
return { modelRoles: session.settings.getModelRoles(),
|
|
@@ -204,7 +228,8 @@ export default function hostExtension(pi: ExtensionAPI): void {
|
|
|
204
228
|
if (!Array.isArray(mounted) || mounted.length)
|
|
205
229
|
throw new ReviewIsolationError("Static PR review cannot establish an empty native device tool set");
|
|
206
230
|
if (!Array.isArray(session.agent.state.tools) || session.agent.state.tools.length ||
|
|
207
|
-
!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)
|
|
208
233
|
throw new ReviewIsolationError("Static PR review found native tools, skills, or autonomous execution enabled");
|
|
209
234
|
return { version: 1, cwd, modelApi: model.api };
|
|
210
235
|
};
|
|
@@ -218,7 +243,7 @@ export default function hostExtension(pi: ExtensionAPI): void {
|
|
|
218
243
|
const extensions = runner.getLoadedExtensions();
|
|
219
244
|
const other = extensions.filter(extension => extension.resolvedPath !== self);
|
|
220
245
|
// Stock SDKs may register their internal autoresearch factory and its
|
|
221
|
-
// default-inactive tools even with
|
|
246
|
+
// default-inactive tools even with an empty selection. No ambient extension or
|
|
222
247
|
// arbitrary inline factory may be active in a review session.
|
|
223
248
|
if (!extensions.some(extension => extension.resolvedPath === self && runner.isExtensionActive(extension.path))
|
|
224
249
|
|| other.some(extension => !/^<inline-\d+>$/.test(extension.resolvedPath)
|
|
@@ -278,8 +303,13 @@ export default function hostExtension(pi: ExtensionAPI): void {
|
|
|
278
303
|
return entry.id;
|
|
279
304
|
} catch (error) { observationHeld = true; throw error; }
|
|
280
305
|
};
|
|
281
|
-
const
|
|
282
|
-
const
|
|
306
|
+
const assertSameRoot = (identity: ReturnType<typeof exact>) => {
|
|
307
|
+
const current = exact();
|
|
308
|
+
if (current.ref !== identity.ref || current.session !== identity.session
|
|
309
|
+
|| current.id !== identity.id || current.file !== identity.file)
|
|
310
|
+
throw new Error("Native root changed during ownership observation");
|
|
311
|
+
};
|
|
312
|
+
const observeOwned = async (identity: ReturnType<typeof exact>, drain: boolean) => {
|
|
283
313
|
const registry = pi.pi.AgentRegistry.global();
|
|
284
314
|
const refs = registry.list();
|
|
285
315
|
const refEpoch = refs.map(ref => [ref.id, ref.generation, ref.parentId, ref.session?.instanceKey, ref.sessionFile]);
|
|
@@ -363,10 +393,10 @@ export default function hostExtension(pi: ExtensionAPI): void {
|
|
|
363
393
|
}
|
|
364
394
|
const scopedServices = async () => (await observeServices()).filter(unit => unit.owner && owners.has(unit.owner));
|
|
365
395
|
const services = await scopedServices();
|
|
396
|
+
assertSameRoot(identity);
|
|
366
397
|
const currentRefs = registry.list();
|
|
367
|
-
if (
|
|
368
|
-
|
|
369
|
-
throw new Error("Native ownership tree changed during service observation");
|
|
398
|
+
if (currentRefs.length !== refs.length || refs.some((ref, index) => currentRefs[index] !== ref))
|
|
399
|
+
throw new DescendantOwnershipChanged("Native ownership tree changed during service observation");
|
|
370
400
|
const deliveriesPending = (session: NativeSession) => {
|
|
371
401
|
const delivery = session.getAsyncJobSnapshot({ recentLimit: 0 })?.delivery;
|
|
372
402
|
return !!delivery && (delivery.delivering || delivery.queued > 0 || delivery.pendingJobIds.length > 0);
|
|
@@ -454,12 +484,28 @@ export default function hostExtension(pi: ExtensionAPI): void {
|
|
|
454
484
|
if (!isDeepStrictEqual(services, refreshed))
|
|
455
485
|
throw new Error("Native services changed while their durable completion evidence was drained");
|
|
456
486
|
}
|
|
487
|
+
assertSameRoot(identity);
|
|
457
488
|
if (!isDeepStrictEqual(refEpoch, registry.list().map(ref =>
|
|
458
489
|
[ref.id, ref.generation, ref.parentId, ref.session?.instanceKey, ref.sessionFile])))
|
|
459
|
-
throw new
|
|
490
|
+
throw new DescendantOwnershipChanged("Native descendant identity changed during completion readback");
|
|
460
491
|
const tree = identity.session.getAsyncJobTree({ recentLimit: 0 });
|
|
461
|
-
|
|
462
|
-
|
|
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 };
|
|
495
|
+
};
|
|
496
|
+
const owned = async (drain = false) => {
|
|
497
|
+
const identity = exact();
|
|
498
|
+
// Stock OMP registers a child before attaching its session. Each
|
|
499
|
+
// transition can invalidate a different read. Rebuild all evidence
|
|
500
|
+
// together, and never retry a maintenance drain.
|
|
501
|
+
for (let remaining = drain ? 0 : 2; ; remaining--) {
|
|
502
|
+
try {
|
|
503
|
+
return await observeOwned(identity, drain);
|
|
504
|
+
} catch (error) {
|
|
505
|
+
if (remaining === 0 || !(error instanceof DescendantOwnershipChanged)) throw error;
|
|
506
|
+
assertSameRoot(identity);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
463
509
|
};
|
|
464
510
|
const localIdle = () => {
|
|
465
511
|
const { session } = exact();
|
|
@@ -469,30 +515,82 @@ export default function hostExtension(pi: ExtensionAPI): void {
|
|
|
469
515
|
&& !session.yieldQueue.has()
|
|
470
516
|
&& !session.getGoalModeState()?.enabled;
|
|
471
517
|
};
|
|
472
|
-
const
|
|
473
|
-
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;
|
|
474
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
|
+
}
|
|
475
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;
|
|
476
542
|
const model = session.model;
|
|
477
|
-
if (!file ||
|
|
478
|
-
|| typeof usage.percent !== "number" || !Number.isFinite(usage.percent) || usage.percent < 50
|
|
479
|
-
|| !Number.isFinite(usage.contextWindow) || usage.contextWindow <= 0
|
|
543
|
+
if (!file || mode === undefined && (contextPercent === null || contextPercent < 50)
|
|
480
544
|
|| !model || typeof model.reasoning !== "boolean" || typeof session.configuredThinkingLevel !== "function") return null;
|
|
481
545
|
const { modelRoles, defaultThinkingLevel } = snapshot();
|
|
482
546
|
const roles = Object.fromEntries(Object.entries(modelRoles).filter((entry): entry is [string, string] =>
|
|
483
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
|
+
}
|
|
484
564
|
return { hostPid: process.pid, sessionId: id, sessionFile: file, nativeRun: runOrdinal,
|
|
485
|
-
contextPercent
|
|
486
|
-
|
|
565
|
+
contextPercent,
|
|
566
|
+
...(hibernation ? { hibernation } : {}),
|
|
567
|
+
selection: { provider: model.provider, modelId: model.id, modelIdentity, reasoning: model.reasoning,
|
|
568
|
+
stockLaunchReplay, ...tierSelection,
|
|
487
569
|
thinkingLevel: session.thinkingLevel ?? null, configuredThinkingLevel: session.configuredThinkingLevel() ?? null,
|
|
488
570
|
modelSettings: { modelRoles: roles, ...(defaultThinkingLevel !== undefined ? { defaultThinkingLevel } : {}) } } };
|
|
489
571
|
};
|
|
490
572
|
const handle = async (command: Frame): Promise<unknown> => {
|
|
573
|
+
if (command.type === "stage_reply_voice" || command.type === "clear_reply_voice") {
|
|
574
|
+
exact();
|
|
575
|
+
if (!replyVoice || typeof command.token !== "string" || !command.token)
|
|
576
|
+
throw new Error("Native reply voice control is unavailable");
|
|
577
|
+
if (command.type === "stage_reply_voice") return { staged: replyVoice.stage(command) };
|
|
578
|
+
replyVoice.clear(command.token);
|
|
579
|
+
return {};
|
|
580
|
+
}
|
|
491
581
|
if (command.type === "get_head_rotation") {
|
|
492
|
-
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);
|
|
493
591
|
if (!state) return null;
|
|
494
592
|
let attestation: Parameters<RotationProbeEvent["respond"]>[0] | undefined;
|
|
495
|
-
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);
|
|
496
594
|
return attestation ?? null;
|
|
497
595
|
}
|
|
498
596
|
if (command.type === "get_session_stats") return exact().session.getSessionStats();
|
|
@@ -531,6 +629,7 @@ export default function hostExtension(pi: ExtensionAPI): void {
|
|
|
531
629
|
}
|
|
532
630
|
if (command.type === "interrupt_maintenance") {
|
|
533
631
|
const { session } = exact();
|
|
632
|
+
replyVoice?.clear();
|
|
534
633
|
const restored = command.restoreQueue === true ? session.clearQueue({ forInterrupt: true }) : undefined;
|
|
535
634
|
// abort() raises its barrier and withdraws marked internal context before
|
|
536
635
|
// its first await. Do not await its compaction cleanup until the owner has
|
|
@@ -551,9 +650,15 @@ export default function hostExtension(pi: ExtensionAPI): void {
|
|
|
551
650
|
}
|
|
552
651
|
if (command.type === "activate") {
|
|
553
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");
|
|
554
659
|
if (reviewCwd) {
|
|
555
|
-
if (command.
|
|
556
|
-
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");
|
|
557
662
|
reviewPolicy(identity.session, reviewCwd);
|
|
558
663
|
}
|
|
559
664
|
// Native's default tool selection omits the goal tool. Add it only for
|
|
@@ -561,7 +666,9 @@ export default function hostExtension(pi: ExtensionAPI): void {
|
|
|
561
666
|
if (command.toolsExplicitlySelected === false && command.noTools === false
|
|
562
667
|
&& goalEnabled.get(readOnly(identity.session.settings)) === true)
|
|
563
668
|
await pi.setActiveTools([...new Set([...pi.getActiveTools(), "goal"])]);
|
|
564
|
-
|
|
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);
|
|
565
672
|
return {};
|
|
566
673
|
}
|
|
567
674
|
if (command.type === "observe") {
|
|
@@ -580,15 +687,56 @@ export default function hostExtension(pi: ExtensionAPI): void {
|
|
|
580
687
|
// The owner requires this first snapshot before opening its public socket.
|
|
581
688
|
const prReviewPolicy = reviewCwd ? reviewPolicy(ownership.identity.session, reviewCwd) : undefined;
|
|
582
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;
|
|
583
700
|
// Only an owner that implements the cursor command can advertise it to peers.
|
|
584
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
|
+
} : {}),
|
|
585
710
|
journalCursorControlVersion: 1,
|
|
711
|
+
...(replyVoice?.available() ? { replyVoiceControlVersion: 2 } : {}),
|
|
712
|
+
...(running ? { headJobs: { running: running.map(job => job.id), awaitingOnly } } : {}),
|
|
713
|
+
fastMode: headFastMode(ownership.identity.session),
|
|
586
714
|
hasOwnedRunningWork: ownership.unknown ? undefined : ownership.busy, mutationHeld, observationHeld,
|
|
587
715
|
admitted: ownership.identity.session.hasAdmittedSubmission,
|
|
588
716
|
postPromptWork: ownership.identity.session.hasPostPromptWork,
|
|
589
717
|
...(typeof ownership.identity.session.configuredThinkingLevel === "function"
|
|
590
718
|
? { configuredThinkingLevel: ownership.identity.session.configuredThinkingLevel() ?? null } : {}) };
|
|
591
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
|
+
}
|
|
592
740
|
if (command.type === "set_lane_model") {
|
|
593
741
|
if (reviewCwd || process.env.OMP_SUPERAGENT_ROLE !== "lane")
|
|
594
742
|
throw new Error("An ordinary managed lane Host is required");
|
|
@@ -677,8 +825,8 @@ export default function hostExtension(pi: ExtensionAPI): void {
|
|
|
677
825
|
if (!model) throw new Error("Native model resolution failed; mutation remains held");
|
|
678
826
|
const expectedLevel = "thinkingLevel" in selected && selected.thinkingLevel !== undefined
|
|
679
827
|
? selected.thinkingLevel : preset.defaultThinkingLevel;
|
|
680
|
-
const effectiveLevel = expectedLevel === "auto"
|
|
681
|
-
: expectedLevel ===
|
|
828
|
+
const effectiveLevel = expectedLevel === "auto" || expectedLevel === "off" ? expectedLevel
|
|
829
|
+
: expectedLevel === "inherit" ? undefined : clampThinkingLevelForModel(model, expectedLevel);
|
|
682
830
|
if (!command.preserveActiveModel) {
|
|
683
831
|
await ownership.identity.session.setModelTemporary(model, expectedLevel);
|
|
684
832
|
}
|
|
@@ -691,6 +839,10 @@ export default function hostExtension(pi: ExtensionAPI): void {
|
|
|
691
839
|
return { name: command.name, settingsScope: "session", preset: snapshot(), model: ownership.identity.session.model };
|
|
692
840
|
}
|
|
693
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");
|
|
694
846
|
if (!localIdle()) throw new Error("session_busy");
|
|
695
847
|
const ownership = await owned(true);
|
|
696
848
|
await ownership.identity.session.waitForIdle();
|
|
@@ -698,11 +850,11 @@ export default function hostExtension(pi: ExtensionAPI): void {
|
|
|
698
850
|
const finalOwnership = await owned(true);
|
|
699
851
|
if (exact().ref !== ownership.identity.ref || !localIdle() || ownership.unknown || finalOwnership.unknown
|
|
700
852
|
|| ownership.busy || finalOwnership.busy) throw new Error("session_busy");
|
|
701
|
-
if (typeof
|
|
702
|
-
const state = rotationState();
|
|
853
|
+
if (typeof headRotation === "string") {
|
|
854
|
+
const state = rotationState(mode);
|
|
703
855
|
if (!state) throw new Error("session_busy");
|
|
704
856
|
let allowed = false;
|
|
705
|
-
pi.events.emit(HEAD_ROTATION_GUARD, { id:
|
|
857
|
+
pi.events.emit(HEAD_ROTATION_GUARD, { id: headRotation, mode, state,
|
|
706
858
|
respond: value => { allowed = value; } } satisfies RotationGuardEvent);
|
|
707
859
|
if (!allowed) throw new Error("session_busy");
|
|
708
860
|
}
|
|
@@ -810,13 +962,27 @@ export default function hostExtension(pi: ExtensionAPI): void {
|
|
|
810
962
|
context = ctx;
|
|
811
963
|
const identity = exact();
|
|
812
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
|
+
}
|
|
813
974
|
if (reviewCwd) {
|
|
814
975
|
try { await armReview(identity.session, reviewCwd); }
|
|
815
976
|
catch (error) {
|
|
816
977
|
process.stderr.write(`${error instanceof ReviewIsolationError ? error.message : "Static PR review native guard setup failed"}\n`);
|
|
817
978
|
throw error;
|
|
818
979
|
}
|
|
819
|
-
}
|
|
980
|
+
} else replyVoice = installReplyVoice(pi, identity.session, async token => {
|
|
981
|
+
const response = await ownerChannel?.request({ type: "claim_reply_voice", token });
|
|
982
|
+
return response?.success === true && isDeepStrictEqual(response.data, { claimed: true });
|
|
983
|
+
}, token => {
|
|
984
|
+
ownerChannel?.send({ type: "retire_reply_voice", token });
|
|
985
|
+
});
|
|
820
986
|
await ctx.sessionManager.ensureOnDisk();
|
|
821
987
|
if (exact().ref !== identity.ref) throw new Error("Native session changed during materialization");
|
|
822
988
|
identity.session.sessionManager.flushSync();
|
|
@@ -835,7 +1001,11 @@ export default function hostExtension(pi: ExtensionAPI): void {
|
|
|
835
1001
|
if (ownerChannel) { socket.destroy(); return; }
|
|
836
1002
|
const channel = new HostChannel(socket, socket, true);
|
|
837
1003
|
ownerChannel = channel;
|
|
838
|
-
void channel.exited.then(() => {
|
|
1004
|
+
void channel.exited.then(() => {
|
|
1005
|
+
if (ownerChannel !== channel) return;
|
|
1006
|
+
ownerChannel = undefined;
|
|
1007
|
+
replyVoice?.clear();
|
|
1008
|
+
});
|
|
839
1009
|
channel.encoder.setProtocolVersion(2);
|
|
840
1010
|
channel.on("frame", (command: Frame) => {
|
|
841
1011
|
if (command.type === "response" || typeof command.id !== "string") return;
|