omp-superagent 0.1.10 → 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.
Files changed (149) hide show
  1. package/DESIGN.md +58 -15
  2. package/README.ko.md +7 -0
  3. package/README.md +7 -0
  4. package/THIRD_PARTY_NOTICES.md +35 -436
  5. package/assets/architecture-dark.svg +7 -12
  6. package/assets/architecture.ko-dark.svg +7 -12
  7. package/assets/architecture.ko.svg +7 -12
  8. package/assets/architecture.mmd +5 -13
  9. package/assets/architecture.svg +7 -12
  10. package/config.example.json +1 -0
  11. package/docs/OPERATIONS.en.md +106 -52
  12. package/docs/OPERATIONS.md +98 -44
  13. package/docs/design/execution.md +80 -52
  14. package/docs/design/messaging.md +113 -32
  15. package/docs/releases/0.1.11.md +18 -0
  16. package/gateway/bin/omp-gateway-darwin-arm64 +0 -0
  17. package/gateway/bin/omp-gateway-darwin-x64 +0 -0
  18. package/gateway/bin/omp-gateway-linux-arm64 +0 -0
  19. package/gateway/bin/omp-gateway-linux-x64 +0 -0
  20. package/host-owner/bin/omp-host-owner-darwin-arm64 +0 -0
  21. package/host-owner/bin/omp-host-owner-darwin-x64 +0 -0
  22. package/host-owner/bin/omp-host-owner-linux-arm64 +0 -0
  23. package/host-owner/bin/omp-host-owner-linux-x64 +0 -0
  24. package/package.json +10 -11
  25. package/scripts/{prepare-ulw.ts → prepare-super.ts} +1 -1
  26. package/skills/head/SKILL.md +12 -3
  27. package/skills/head/references/routing.md +1 -1
  28. package/skills/head/references/supervision.md +23 -26
  29. package/skills/lane/SKILL.md +28 -21
  30. package/skills/lane/references/workflow.md +15 -17
  31. package/src/cli.ts +33 -33
  32. package/src/{config.ts → config/config.ts} +7 -3
  33. package/src/config/wake-config.ts +36 -0
  34. package/src/contracts.ts +61 -12
  35. package/src/{cron-jobs.ts → cron/cron-jobs.ts} +21 -13
  36. package/src/{cron-pr-intake.ts → cron/cron-pr-intake.ts} +4 -4
  37. package/src/{cron-schedule.ts → cron/cron-schedule.ts} +3 -3
  38. package/src/extension.ts +43 -25
  39. package/src/{gateway-client.ts → gateway/gateway-client.ts} +89 -32
  40. package/src/{gateway-native.ts → gateway/gateway-native.ts} +4 -4
  41. package/src/{gateway-protocol.ts → gateway/gateway-protocol.ts} +69 -14
  42. package/src/{gateway-wire.ts → gateway/gateway-wire.ts} +12 -7
  43. package/src/gateway-config.ts +1 -1
  44. package/src/gateway-restart-env.ts +3 -3
  45. package/src/{group-access.ts → group/group-access.ts} +8 -3
  46. package/src/{group-policy.ts → group/group-policy.ts} +2 -2
  47. package/src/{group-runner.ts → group/group-runner.ts} +11 -6
  48. package/src/host-extension.ts +164 -36
  49. package/src/host-sdk-helper.ts +62 -65
  50. package/src/{decision-tool.ts → lane/decision-tool.ts} +12 -4
  51. package/src/{decisions.ts → lane/decisions.ts} +12 -10
  52. package/src/{lane-models.ts → lane/lane-models.ts} +1 -1
  53. package/src/{lane-rows.ts → lane/lane-rows.ts} +2 -2
  54. package/src/{lane-watch.ts → lane/lane-watch.ts} +6 -2
  55. package/src/{workflow.ts → lane/workflow.ts} +1 -1
  56. package/src/lane-extension.ts +25 -7
  57. package/src/managed-memory-helper.ts +2 -2
  58. package/src/{managed-ulw-probe.ts → managed-super-probe.ts} +3 -3
  59. package/src/{delivery.ts → messaging/delivery.ts} +1 -1
  60. package/src/{discord-command-registration.ts → messaging/discord-command-registration.ts} +3 -2
  61. package/src/{discord-context.ts → messaging/discord-context.ts} +1 -1
  62. package/src/{messenger-command-catalog.json → messaging/messenger-command-catalog.json} +1 -0
  63. package/src/messaging/messenger-commands.ts +55 -0
  64. package/src/{result-attachment.ts → messaging/result-attachment.ts} +3 -3
  65. package/src/{slack-command-registration.ts → messaging/slack-command-registration.ts} +3 -3
  66. package/src/{telegram-command-registration.ts → messaging/telegram-command-registration.ts} +2 -2
  67. package/src/omp/head-resume.ts +123 -0
  68. package/src/{host-owner-path.ts → omp/host-owner-path.ts} +1 -1
  69. package/src/{host-protocol.ts → omp/host-protocol.ts} +10 -2
  70. package/src/{host-superkit.ts → omp/host-superkit.ts} +1 -1
  71. package/src/{host.ts → omp/host.ts} +26 -17
  72. package/src/{installed-omp.ts → omp/installed-omp.ts} +1 -1
  73. package/src/{managed-memory.ts → omp/managed-memory.ts} +2 -2
  74. package/src/{managed-ulw.ts → omp/managed-super.ts} +42 -16
  75. package/src/omp/native-journal.ts +124 -0
  76. package/src/{native-launch-profile.ts → omp/native-launch-profile.ts} +6 -2
  77. package/src/{native-presets.ts → omp/native-presets.ts} +2 -2
  78. package/src/omp/native-sessions.ts +124 -0
  79. package/src/{omp-usage.ts → omp/omp-usage.ts} +1 -1
  80. package/src/{soul.ts → omp/soul.ts} +2 -2
  81. package/src/omp/stock-head-launch.ts +31 -0
  82. package/src/{autostart.ts → operator/autostart.ts} +3 -3
  83. package/src/{operator.ts → operator/operator.ts} +2 -2
  84. package/src/{setup-judge.ts → operator/setup-judge.ts} +1 -1
  85. package/src/{setup-profiles.ts → operator/setup-profiles.ts} +2 -2
  86. package/src/{setup.ts → operator/setup.ts} +5 -5
  87. package/src/{pr-intake-automation.ts → pr/pr-intake-automation.ts} +1 -1
  88. package/src/{pr-intake-mode.ts → pr/pr-intake-mode.ts} +3 -3
  89. package/src/{pr-intake-review.ts → pr/pr-intake-review.ts} +5 -5
  90. package/src/{pr-intake-work.ts → pr/pr-intake-work.ts} +1 -1
  91. package/src/{pr-review-models.ts → pr/pr-review-models.ts} +2 -2
  92. package/src/{pr-watch.ts → pr/pr-watch.ts} +36 -26
  93. package/src/{message-order.ts → routing/message-order.ts} +1 -1
  94. package/src/{topic-history.ts → routing/topic-history.ts} +2 -2
  95. package/src/{topic-request.ts → routing/topic-request.ts} +4 -2
  96. package/src/{runtime.ts → runtime/controller.ts} +867 -1213
  97. package/src/runtime/deferred-routing.ts +106 -0
  98. package/src/runtime/dm-timeline.ts +194 -0
  99. package/src/{head-recovery.ts → runtime/head-recovery.ts} +1 -1
  100. package/src/{head-rotation.ts → runtime/head-rotation.ts} +32 -5
  101. package/src/runtime/model-journal.ts +119 -0
  102. package/src/runtime/native-frames.ts +131 -0
  103. package/src/{observation-request.ts → runtime/observation-request.ts} +1 -1
  104. package/src/runtime/preset-sync.ts +232 -0
  105. package/src/runtime/preset-watch-paths.ts +137 -0
  106. package/src/runtime/result-attachments.ts +146 -0
  107. package/src/storage/deferred-routing.ts +149 -0
  108. package/src/{store.ts → storage/store.ts} +75 -42
  109. package/src/{worker-bridge.ts → worker/worker-bridge.ts} +2 -2
  110. package/src/{worker-enrollment.ts → worker/worker-enrollment.ts} +2 -2
  111. package/src/{worker-host.ts → worker/worker-host.ts} +7 -3
  112. package/src/{worker-placement.ts → worker/worker-placement.ts} +1 -1
  113. package/src/{worker-profile.ts → worker/worker-profile.ts} +1 -1
  114. package/src/{worker-registration.ts → worker/worker-registration.ts} +2 -2
  115. package/src/{worker-request.ts → worker/worker-request.ts} +5 -5
  116. package/src/{worker-service.ts → worker/worker-service.ts} +2 -2
  117. package/src/{worker-trust.ts → worker/worker-trust.ts} +1 -1
  118. package/src/{worker-wire.ts → worker/worker-wire.ts} +3 -3
  119. package/src/worker-serve-prepare.ts +4 -4
  120. package/src/board-extension.ts +0 -217
  121. package/src/board.ts +0 -467
  122. package/src/gateway-host-helper.ts +0 -13
  123. package/src/messenger-commands.ts +0 -15
  124. package/src/native-sessions.ts +0 -34
  125. /package/src/{credentials.ts → config/credentials.ts} +0 -0
  126. /package/src/{lane-report.ts → lane/lane-report.ts} +0 -0
  127. /package/src/{dialog.ts → messaging/dialog.ts} +0 -0
  128. /package/src/{telegram-command-languages.json → messaging/telegram-command-languages.json} +0 -0
  129. /package/src/{host-broker-services.ts → omp/host-broker-services.ts} +0 -0
  130. /package/src/{host-inventory-manifest.ts → omp/host-inventory-manifest.ts} +0 -0
  131. /package/src/{host-reply-voice.ts → omp/host-reply-voice.ts} +0 -0
  132. /package/src/{host-services.ts → omp/host-services.ts} +0 -0
  133. /package/src/{native-settings.ts → omp/native-settings.ts} +0 -0
  134. /package/src/{superkit-skills.ts → omp/superkit-skills.ts} +0 -0
  135. /package/src/{repository.ts → operator/repository.ts} +0 -0
  136. /package/src/{pr-github-schema.ts → pr/pr-github-schema.ts} +0 -0
  137. /package/src/{pr-github.ts → pr/pr-github.ts} +0 -0
  138. /package/src/{pr-intake-comment.ts → pr/pr-intake-comment.ts} +0 -0
  139. /package/src/{pr-intake-fix.ts → pr/pr-intake-fix.ts} +0 -0
  140. /package/src/{pr-intake-github.ts → pr/pr-intake-github.ts} +0 -0
  141. /package/src/{pr-intake-material.ts → pr/pr-intake-material.ts} +0 -0
  142. /package/src/{pr-intake-tree.ts → pr/pr-intake-tree.ts} +0 -0
  143. /package/src/{head-quota.ts → runtime/head-quota.ts} +0 -0
  144. /package/src/{worker-checkout.ts → worker/worker-checkout.ts} +0 -0
  145. /package/src/{worker-destination.ts → worker/worker-destination.ts} +0 -0
  146. /package/src/{worker-doctor.ts → worker/worker-doctor.ts} +0 -0
  147. /package/src/{worker-ledger.ts → worker/worker-ledger.ts} +0 -0
  148. /package/src/{worker-repository.ts → worker/worker-repository.ts} +0 -0
  149. /package/upstream/{ulw.json → super.json} +0 -0
@@ -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 "./group-runner-extension";
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("./group-runner-extension.ts", import.meta.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-tools", "--no-extensions", "--no-context-files", "--no-rules",
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
- marketplace: { autoUpdate: false }, telemetry: { otlpExportEnabled: false },
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" ? ["--extension", "--tools", "--approval-mode"] : [])];
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
@@ -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 } from "@oh-my-pi/pi-coding-agent/config/model-resolver";
12
- import { resolveThinkingLevelForModel } from "@oh-my-pi/pi-tui/thinking";
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-ulw";
23
- import { verifyHostSuperkit } from "./host-superkit";
24
- import { isPrReviewInferenceModel, prReviewModelChoices } from "./pr-review-models";
25
- import { HEAD_ROTATION_GUARD, HEAD_ROTATION_PROBE, type RotationGuardEvent,
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
- // --no-tools can still leave builtins in the registration catalogue: write
40
- // on stock 19.0, resolution/QA devices on 19.1. None may be enabled, mounted,
41
- // presented to the provider, or executed by the restricted session.
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, "compaction.enabled": false, "advisor.enabled": false, "autolearn.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 || session.getGoalModeState()?.enabled)
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 --no-tools. No ambient extension or
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
- return { identity, tree, unknown: servicesUnknown || serviceDeliveryUnknown || descendantsUnknown(),
471
- busy: liveGenerations.size > 0 || descendantsBusy() || deliveriesPending(identity.session) || !!tree?.running.length };
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 rotationState = (): RotationNative | null => {
496
- if (process.env.OMP_SUPERAGENT_ROLE !== "head" || !localIdle()) return null;
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 || !usage || typeof usage.tokens !== "number" || !Number.isFinite(usage.tokens)
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: usage.percent,
509
- selection: { provider: model.provider, modelId: model.id, reasoning: model.reasoning,
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 state = rotationState();
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.noTools !== true || command.toolsExplicitlySelected !== false)
588
- throw new Error("Static PR review requires the native no-tools launch selection");
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
- pi.events.emit("superagent:host-ready", { sessionId: identity.id, sessionFile: identity.file, pid: process.pid });
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" ? "auto"
714
- : expectedLevel === undefined ? undefined : resolveThinkingLevelForModel(model, 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 command.headRotation === "string") {
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: command.headRotation, state,
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) {