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.
- package/DESIGN.md +58 -15
- package/README.ko.md +7 -0
- package/README.md +7 -0
- 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 +106 -52
- package/docs/OPERATIONS.md +98 -44
- package/docs/design/execution.md +80 -52
- package/docs/design/messaging.md +113 -32
- 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 +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 -33
- 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 +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-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/{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
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { lstat } from "node:fs/promises";
|
|
2
|
+
import { isDeepStrictEqual } from "node:util";
|
|
3
|
+
import type { RotationSelection } from "../runtime/head-rotation";
|
|
4
|
+
import { stockReplayRefusal } from "./stock-head-launch";
|
|
5
|
+
|
|
6
|
+
type HeadResumeInput = {
|
|
7
|
+
readonly argv: readonly string[];
|
|
8
|
+
readonly sessionFile: string;
|
|
9
|
+
readonly sessionId: string;
|
|
10
|
+
readonly selection: RotationSelection;
|
|
11
|
+
readonly checkJournal: boolean;
|
|
12
|
+
readonly rotationOnly?: boolean;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
async function checkHeadResumeJournal(input: HeadResumeInput, needsServiceTier: boolean): Promise<string | undefined> {
|
|
16
|
+
const before = await lstat(input.sessionFile);
|
|
17
|
+
if (!before.isFile()) return "HEAD sleep requires a regular native journal, not a symlink";
|
|
18
|
+
const { loadSessionFile } = await import("@oh-my-pi/pi-coding-agent/session/session-loader");
|
|
19
|
+
const { entries, invalidHeader, malformedRecords, sourceSize } =
|
|
20
|
+
await loadSessionFile(input.sessionFile, undefined, { throwIfMissing: true });
|
|
21
|
+
const after = await lstat(input.sessionFile);
|
|
22
|
+
const [header] = entries;
|
|
23
|
+
if (!after.isFile() || after.dev !== before.dev || after.ino !== before.ino ||
|
|
24
|
+
after.size !== before.size || sourceSize !== before.size ||
|
|
25
|
+
after.mtimeMs !== before.mtimeMs || after.ctimeMs !== before.ctimeMs ||
|
|
26
|
+
invalidHeader || malformedRecords !== 0 || header?.type !== "session" || header.id !== input.sessionId)
|
|
27
|
+
return "HEAD journal changed or could not be read as the exact native session";
|
|
28
|
+
if (entries.some((entry, i) => i !== 0 && entry.type === "session"))
|
|
29
|
+
return "HEAD journal contains a competing native session header";
|
|
30
|
+
const { lastModelChangeRole, SessionEntryIndex } = await import("@oh-my-pi/pi-coding-agent/session/session-manager");
|
|
31
|
+
const index = new SessionEntryIndex();
|
|
32
|
+
const records = entries.filter(entry => entry.type !== "session");
|
|
33
|
+
index.rebuild(records);
|
|
34
|
+
const branch = index.branchView();
|
|
35
|
+
const { buildSessionContext, getRestorableSessionModels } = await import("@oh-my-pi/pi-coding-agent/session/session-context");
|
|
36
|
+
const { models, serviceTier } = buildSessionContext(records, index.leafId(), index.entriesById());
|
|
37
|
+
const saved = getRestorableSessionModels(models, lastModelChangeRole(branch))[0];
|
|
38
|
+
const hasServiceTier = branch.some(entry => entry.type === "service_tier_change");
|
|
39
|
+
if (needsServiceTier && !hasServiceTier)
|
|
40
|
+
return "HEAD cannot remove stock --service-tier without a saved selection on the active journal branch";
|
|
41
|
+
const { selection } = input;
|
|
42
|
+
if (!isDeepStrictEqual(hasServiceTier ? serviceTier ?? {} : selection.serviceTierDefaults, selection.serviceTier))
|
|
43
|
+
return "Stock HEAD resume cannot restore the active service tier from the journal or its native defaults";
|
|
44
|
+
const exact = selection.modelIdentity;
|
|
45
|
+
if (saved === exact) return;
|
|
46
|
+
// Before the first turn stock can leave its model entry in memory only.
|
|
47
|
+
// The restored settings overlay contains the attested effective default,
|
|
48
|
+
// but this fallback cannot override a model stock finds in the journal.
|
|
49
|
+
if (!saved && selection.modelSettings.modelRoles.default === exact) return;
|
|
50
|
+
const { parseModelString } = await import("@oh-my-pi/pi-coding-agent/config/model-selector");
|
|
51
|
+
const parsed = saved && parseModelString(saved, { allowMaxSuffix: true, allowAutoAlias: true });
|
|
52
|
+
if (parsed && `${parsed.provider}/${parsed.id}` === exact) return;
|
|
53
|
+
return "Stock HEAD resume cannot restore the active model from the journal or its exact bootstrap default";
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Prove that stock can restore this exact live selection without replaying one-shot options. */
|
|
57
|
+
export async function headResumeCommand(input: HeadResumeInput) {
|
|
58
|
+
const { argv, sessionFile, selection } = input;
|
|
59
|
+
const { extractProfileFlags } = await import("@oh-my-pi/pi-coding-agent/cli/profile-bootstrap");
|
|
60
|
+
const { setProfile, resolveProfileEnv } = await import("@oh-my-pi/pi-utils/dirs");
|
|
61
|
+
const suffix = ["--mode", "rpc-ui", "--session", sessionFile];
|
|
62
|
+
const original = extractProfileFlags([...argv, ...suffix]);
|
|
63
|
+
setProfile(original.profile ?? resolveProfileEnv(process.env.OMP_PROFILE, process.env.PI_PROFILE));
|
|
64
|
+
const { resolveCliArgv } = await import("@oh-my-pi/pi-coding-agent/cli-commands");
|
|
65
|
+
const { parseArgs } = await import("@oh-my-pi/pi-coding-agent/cli/args");
|
|
66
|
+
const parseStockLaunch = (args: string[]) => {
|
|
67
|
+
const resolved = resolveCliArgv(args);
|
|
68
|
+
return "error" in resolved || resolved.argv[0] !== "launch" ? null : parseArgs(resolved.argv.slice(1));
|
|
69
|
+
};
|
|
70
|
+
const parsed = parseStockLaunch(original.argv);
|
|
71
|
+
const refusal = stockReplayRefusal(parsed, sessionFile);
|
|
72
|
+
if (refusal || !parsed) return { refused: refusal ?? "HEAD wake launch was not parsed" };
|
|
73
|
+
const { flagConsumesValue } = await import("@oh-my-pi/pi-coding-agent/cli/flag-tables");
|
|
74
|
+
const command: string[] = [];
|
|
75
|
+
for (let i = 0; i < argv.length; i++) {
|
|
76
|
+
const token = argv[i];
|
|
77
|
+
const flag = token.split("=", 1)[0];
|
|
78
|
+
const consumesValue = flagConsumesValue(token, argv[i + 1]);
|
|
79
|
+
// The managed --session suffix wins in parseArgs, hiding an earlier
|
|
80
|
+
// selector. Inspect only stock option tokens, not other flags' values.
|
|
81
|
+
if (flag === "--resume" || flag === "-r" || flag === "--session")
|
|
82
|
+
return { refused: "HEAD wake cannot combine competing stock session selectors" };
|
|
83
|
+
if (flag !== "--model" && flag !== "--provider" && flag !== "--thinking" && flag !== "--service-tier") {
|
|
84
|
+
command.push(token);
|
|
85
|
+
if (consumesValue) command.push(argv[i + 1]);
|
|
86
|
+
}
|
|
87
|
+
if (consumesValue) i++;
|
|
88
|
+
}
|
|
89
|
+
if (selection.stockLaunchReplay !== true)
|
|
90
|
+
return { refused: "The original HEAD did not attest that its actual stock launch is replayable" };
|
|
91
|
+
if (input.rotationOnly) return { command: argv };
|
|
92
|
+
if (!selection.modelIdentity || !selection.serviceTier || !selection.serviceTierDefaults || !selection.effectiveServiceTier)
|
|
93
|
+
return { refused: "The original HEAD did not attest its exact routed model and service tier" };
|
|
94
|
+
if (parsed.model && parsed.apiKey)
|
|
95
|
+
return { refused: "Stock --api-key is bound to an explicit --model; HEAD wake cannot rebind it to the saved session model" };
|
|
96
|
+
for (const [role, value] of [["smol", parsed.smol], ["slow", parsed.slow], ["plan", parsed.plan]] as const) {
|
|
97
|
+
if (value && selection.modelSettings.modelRoles[role] !== value)
|
|
98
|
+
return { refused: `HEAD wake cannot replay the conflicting stock --${role} role override` };
|
|
99
|
+
}
|
|
100
|
+
const effort = selection.configuredThinkingLevel ?? undefined;
|
|
101
|
+
if (effort === undefined && selection.reasoning)
|
|
102
|
+
return { refused: "Stock --thinking has no inherit selector for this HEAD's absent reasoning effort" };
|
|
103
|
+
// Let stock restore the branch model and tier. An old --model can overwrite
|
|
104
|
+
// the default role; --service-tier would overwrite even an explicit /fast off.
|
|
105
|
+
// Keep the live configured effort, including auto before it has journaled
|
|
106
|
+
// the first classification.
|
|
107
|
+
if (effort !== undefined) command.push(`--thinking=${effort}`);
|
|
108
|
+
const normalized = extractProfileFlags([...command, ...suffix]);
|
|
109
|
+
const restored = parseStockLaunch(normalized.argv);
|
|
110
|
+
const omitSelection = ({
|
|
111
|
+
model: _model, provider: _provider, thinking: _thinking, serviceTier: _serviceTier, ...other
|
|
112
|
+
}: typeof parsed) => other;
|
|
113
|
+
if (!restored || restored.model !== undefined || restored.provider !== undefined
|
|
114
|
+
|| restored.thinking !== effort || restored.serviceTier !== undefined
|
|
115
|
+
|| normalized.profile !== original.profile || normalized.aliasName !== original.aliasName
|
|
116
|
+
|| !isDeepStrictEqual(omitSelection(restored), omitSelection(parsed)))
|
|
117
|
+
return { refused: "Stock HEAD model, effort and service tier flags cannot be replaced without changing other launch options" };
|
|
118
|
+
if (input.checkJournal) {
|
|
119
|
+
const refused = await checkHeadResumeJournal(input, parsed.serviceTier !== undefined);
|
|
120
|
+
if (refused) return { refused };
|
|
121
|
+
}
|
|
122
|
+
return { command };
|
|
123
|
+
}
|
|
@@ -3,7 +3,7 @@ import { access } from "node:fs/promises";
|
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
4
|
|
|
5
5
|
export const hostOwnerExecutable = fileURLToPath(new URL(
|
|
6
|
-
|
|
6
|
+
`../../host-owner/bin/omp-host-owner-${process.platform}-${process.arch}`, import.meta.url,
|
|
7
7
|
));
|
|
8
8
|
|
|
9
9
|
export async function requireHostOwner(): Promise<string> {
|
|
@@ -4,7 +4,8 @@ import { StringDecoder } from "node:string_decoder";
|
|
|
4
4
|
import { MAX_RPC_REASSEMBLED_BYTES, RpcFrameDecoder, RpcFrameEncoder } from "@oh-my-pi/pi-coding-agent/modes/rpc/rpc-frame";
|
|
5
5
|
import type { RpcResponse, RpcSessionState } from "@oh-my-pi/pi-coding-agent/modes/rpc/rpc-types";
|
|
6
6
|
import type { UnitSnapshot } from "@oh-my-pi/pi-coding-agent/daemon/protocol";
|
|
7
|
-
import type {
|
|
7
|
+
import type { ServiceTierByFamily } from "@oh-my-pi/pi-ai";
|
|
8
|
+
import type { LanePresetSnapshot } from "../contracts";
|
|
8
9
|
|
|
9
10
|
export const PR_REVIEW_SYSTEM_PROMPT = [
|
|
10
11
|
"You are a static pull request reviewer. Review only the material provided in the current request.",
|
|
@@ -17,6 +18,11 @@ export const PR_REVIEW_SYSTEM_PROMPT = [
|
|
|
17
18
|
export const PR_REVIEW_GITHUB_ENV = ["GH_TOKEN", "GITHUB_TOKEN", "GH_ENTERPRISE_TOKEN", "GITHUB_ENTERPRISE_TOKEN"] as const;
|
|
18
19
|
export const LANE_MODEL_PROMOTION_RECEIPT = "superagent_lane_model_promotion";
|
|
19
20
|
|
|
21
|
+
export type FastModeState = {
|
|
22
|
+
readonly mode: "off" | "on" | "ultra";
|
|
23
|
+
readonly active: boolean;
|
|
24
|
+
};
|
|
25
|
+
|
|
20
26
|
/** Private adapter observations, not additions to the stock RPC protocol. */
|
|
21
27
|
export type HostState = RpcSessionState & {
|
|
22
28
|
hostPid: number;
|
|
@@ -26,6 +32,8 @@ export type HostState = RpcSessionState & {
|
|
|
26
32
|
readonly prReviewPolicy?: { readonly version: 1; readonly cwd: string; readonly modelApi: string };
|
|
27
33
|
readonly journalCursorVersion?: 1;
|
|
28
34
|
readonly replyVoiceVersion?: 1 | 2;
|
|
35
|
+
readonly fastMode?: FastModeState;
|
|
36
|
+
readonly serviceTier?: Readonly<ServiceTierByFamily>;
|
|
29
37
|
settingsScope: "session";
|
|
30
38
|
modelSettings: LanePresetSnapshot;
|
|
31
39
|
hasOwnedRunningWork: boolean;
|
|
@@ -39,7 +47,7 @@ export type ServiceUnit = Pick<UnitSnapshot, "id" | "key" | "owner" |
|
|
|
39
47
|
};
|
|
40
48
|
export type Response = Frame & { success: boolean; data?: unknown; error?: string };
|
|
41
49
|
export type HostResponse = RpcResponse | {
|
|
42
|
-
type: "response"; id?: string; command: "shutdown_host" | "set_model_preset" | "set_pr_review_model" | "get_host_admission"; success: true; data: Frame;
|
|
50
|
+
type: "response"; id?: string; command: "shutdown_host" | "set_model_preset" | "set_pr_review_model" | "get_host_admission" | "set_head_fast_mode"; success: true; data: Frame;
|
|
43
51
|
} | {
|
|
44
52
|
type: "response"; id?: string; command: "set_lane_model"; success: true;
|
|
45
53
|
data: { readonly provider: string; readonly id: string };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { realpathSync } from "node:fs";
|
|
2
2
|
import { sep } from "node:path";
|
|
3
3
|
import type { AgentSession } from "@oh-my-pi/pi-coding-agent";
|
|
4
|
-
import { readManagedUlwPackage } from "./managed-
|
|
4
|
+
import { readManagedUlwPackage } from "./managed-super";
|
|
5
5
|
|
|
6
6
|
/** Inspect this stock session's bound factories, not a second SDK loader or launch argv. */
|
|
7
7
|
export async function verifyHostSuperkit(session: AgentSession, selected: string | undefined): Promise<string> {
|
|
@@ -5,6 +5,7 @@ import * as net from "node:net";
|
|
|
5
5
|
import * as path from "node:path";
|
|
6
6
|
import { Readable, type Writable } from "node:stream";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
|
+
import { isDeepStrictEqual } from "node:util";
|
|
8
9
|
import {
|
|
9
10
|
RpcClient,
|
|
10
11
|
type RpcAgentProcess,
|
|
@@ -13,9 +14,9 @@ import { RPC_GOAL_CONTINUATION_MODE } from "@oh-my-pi/pi-coding-agent/modes/rpc/
|
|
|
13
14
|
import { HostChannel, PR_REVIEW_GITHUB_ENV, PR_REVIEW_SYSTEM_PROMPT, type HostResponse, type HostState } from "./host-protocol";
|
|
14
15
|
import { requireHostOwner } from "./host-owner-path";
|
|
15
16
|
import { inspectInstalledOmp, resolveOmpCommand } from "./installed-omp";
|
|
16
|
-
import type { DialogResponse, LanePresetSnapshot } from "
|
|
17
|
-
import type { WorkerHostProfile } from "
|
|
18
|
-
import { activeManagedUlw, managedUlwLaunch, MANAGED_ULW_ENV, MANAGED_ULW_FIXTURE_ENV, MANAGED_ULW_FIXTURE_ROOT_ENV, validateManagedUlwPackage } from "./managed-
|
|
17
|
+
import type { DialogResponse, LanePresetSnapshot } from "../contracts";
|
|
18
|
+
import type { WorkerHostProfile } from "../worker/worker-profile";
|
|
19
|
+
import { activeManagedUlw, managedUlwLaunch, MANAGED_ULW_ENV, MANAGED_ULW_FIXTURE_ENV, MANAGED_ULW_FIXTURE_ROOT_ENV, validateManagedUlwPackage } from "./managed-super";
|
|
19
20
|
|
|
20
21
|
const CONNECT_TIMEOUT_MS = 5_000;
|
|
21
22
|
const START_TIMEOUT_MS = 30_000;
|
|
@@ -28,10 +29,13 @@ export const PR_REVIEW_INPUT_PREFIX = "Static PR review input:\n";
|
|
|
28
29
|
const prReviewSettings = {
|
|
29
30
|
memory: { backend: "off" },
|
|
30
31
|
goal: { enabled: false },
|
|
32
|
+
plan: { enabled: false },
|
|
31
33
|
compaction: { enabled: false },
|
|
32
34
|
advisor: { enabled: false },
|
|
33
35
|
autolearn: { enabled: false },
|
|
34
36
|
dev: { autoqa: false },
|
|
37
|
+
speechgen: { enabled: false },
|
|
38
|
+
externalThinking: false,
|
|
35
39
|
skills: { enabled: false, enableSkillCommands: false, customDirectories: [] },
|
|
36
40
|
mcp: { enableProjectConfig: false },
|
|
37
41
|
marketplace: { autoUpdate: "off" },
|
|
@@ -348,10 +352,12 @@ export async function buildHostArgs(options: HostOptions, configPath = `${option
|
|
|
348
352
|
}
|
|
349
353
|
if (options.prReviewOnly) {
|
|
350
354
|
await assertPrReviewLaunch(options);
|
|
355
|
+
// Both stock interfaces accept an explicit empty built-in list. Unlike
|
|
356
|
+
// --no-tools in OMP 19.2, this permits the exact trusted lifecycle module.
|
|
351
357
|
return ["--mode", "rpc-ui", "--session", options.sessionFile, "--cwd", options.cwd,
|
|
352
|
-
"--
|
|
358
|
+
"--tools=", "--no-extensions", "--no-lsp", "--no-skills", "--no-rules", "--no-context-files",
|
|
353
359
|
"--no-title", "--no-prewalk", "--offline",
|
|
354
|
-
"--trusted-extension", await fs.realpath(fileURLToPath(new URL("
|
|
360
|
+
"--trusted-extension", await fs.realpath(fileURLToPath(new URL("../host-extension.ts", import.meta.url))),
|
|
355
361
|
"--system-prompt", PR_REVIEW_SYSTEM_PROMPT, "--config", configPath];
|
|
356
362
|
}
|
|
357
363
|
if (options.modelPreset) {
|
|
@@ -363,9 +369,8 @@ export async function buildHostArgs(options: HostOptions, configPath = `${option
|
|
|
363
369
|
}
|
|
364
370
|
const managedUlwPath = selectManagedUlw(options);
|
|
365
371
|
const extensions = composition?.extensionPaths ?? [
|
|
366
|
-
fileURLToPath(new URL("
|
|
367
|
-
fileURLToPath(new URL("
|
|
368
|
-
fileURLToPath(new URL("./host-extension.ts", import.meta.url)),
|
|
372
|
+
fileURLToPath(new URL("../../", import.meta.url)), managedUlwPath, options.extensionPath,
|
|
373
|
+
fileURLToPath(new URL("../host-extension.ts", import.meta.url)),
|
|
369
374
|
];
|
|
370
375
|
return [
|
|
371
376
|
"--mode", "rpc-ui",
|
|
@@ -410,7 +415,7 @@ async function launchHost(options: HostOptions, beforeSessionPrepare?: () => voi
|
|
|
410
415
|
})) throw new Error("Static PR review workspace must be outside a Git checkout");
|
|
411
416
|
if (path.dirname(dir) === dir) break;
|
|
412
417
|
}
|
|
413
|
-
const { assertWorkerWorkspaceStartup } = await import("
|
|
418
|
+
const { assertWorkerWorkspaceStartup } = await import("../worker/worker-profile");
|
|
414
419
|
assertWorkerWorkspaceStartup(cwd, options.env.HOME ?? "");
|
|
415
420
|
const env = { ...options.env };
|
|
416
421
|
for (const name of [...PR_REVIEW_GITHUB_ENV,
|
|
@@ -478,15 +483,15 @@ async function launchHost(options: HostOptions, beforeSessionPrepare?: () => voi
|
|
|
478
483
|
}
|
|
479
484
|
const manifestPath = path.join(launchDirectory, "owner.json");
|
|
480
485
|
const { env: _inheritedEnvironment, worker: _workerProfile, ...launchOptions } = options;
|
|
481
|
-
const helperPath = fileURLToPath(new URL("
|
|
486
|
+
const helperPath = fileURLToPath(new URL("../host-sdk-helper.ts", import.meta.url));
|
|
482
487
|
let manifest: Record<string, unknown> | undefined;
|
|
483
|
-
const extensionPaths = managedUlwPath === undefined ? [] : [fileURLToPath(new URL("
|
|
484
|
-
managedUlwPath, options.extensionPath,
|
|
485
|
-
fileURLToPath(new URL("
|
|
488
|
+
const extensionPaths = managedUlwPath === undefined ? [] : [fileURLToPath(new URL("../../", import.meta.url)),
|
|
489
|
+
managedUlwPath, options.extensionPath,
|
|
490
|
+
fileURLToPath(new URL("../host-extension.ts", import.meta.url))];
|
|
486
491
|
// The same helper discovers composition and then prepares the session.
|
|
487
492
|
// The worker launch fence is committed only immediately before the manifest
|
|
488
493
|
// is sent. Preparation and owner startup share the same deadline.
|
|
489
|
-
const { prepared, deadline } = await managedUlwLaunch({ cwd: options.cwd, managedUlwPath,
|
|
494
|
+
const { composition, prepared, deadline } = await managedUlwLaunch({ cwd: options.cwd, managedUlwPath,
|
|
490
495
|
extensionPaths, configPath, parentConfigPath: process.env.OMP_SUPERAGENT_HOST_CONFIG, commandArgs: options.command.slice(1),
|
|
491
496
|
...(options.worker ? { worker: { extensionPaths: options.worker.extensionPaths } } : {}),
|
|
492
497
|
launchArgs: managedUlwPath === undefined ? [] : [...options.command.slice(1), ...await buildHostArgs(options, configPath)],
|
|
@@ -504,10 +509,14 @@ async function launchHost(options: HostOptions, beforeSessionPrepare?: () => voi
|
|
|
504
509
|
const flags = JSON.parse(prepared);
|
|
505
510
|
if (typeof flags?.toolsExplicitlySelected !== "boolean" || typeof flags.noTools !== "boolean")
|
|
506
511
|
throw new Error("Native session preparation did not confirm tool selection");
|
|
507
|
-
if (options.prReviewOnly && (
|
|
508
|
-
throw new Error("Native launch did not resolve
|
|
512
|
+
if (options.prReviewOnly && (flags.emptyToolSelection !== true || flags.noTools || !flags.toolsExplicitlySelected))
|
|
513
|
+
throw new Error("Native launch did not resolve an explicit empty tool selection");
|
|
514
|
+
if (!options.prReviewOnly && !options.worker && (!composition.nativeProfile
|
|
515
|
+
|| !isDeepStrictEqual(flags.nativeProfileBinding?.profile, composition.nativeProfile)))
|
|
516
|
+
throw new Error("Native preparation did not bind the local Host's discovery profile");
|
|
509
517
|
await fs.writeFile(manifestPath, JSON.stringify({ ...manifest, toolsExplicitlySelected: flags.toolsExplicitlySelected,
|
|
510
|
-
noTools: flags.noTools,
|
|
518
|
+
noTools: flags.noTools, ...(options.prReviewOnly ? { emptyToolSelection: true } : {}),
|
|
519
|
+
inventory: flags.inventory, nativeProfileBinding: flags.nativeProfileBinding, replayableArgvHash: flags.replayableArgvHash }), { flag: "wx", mode: 0o600 });
|
|
511
520
|
if (performance.now() >= deadline) throw new Error("Native Host startup timed out before launch");
|
|
512
521
|
child = spawn(hostOwnerExecutable, [manifestPath], {
|
|
513
522
|
cwd: options.cwd, env: options.env,
|
|
@@ -2,7 +2,7 @@ import { closeSync, constants, fstatSync, openSync, readSync, realpathSync, stat
|
|
|
2
2
|
import { basename, delimiter, dirname, isAbsolute, join, resolve } from "node:path";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
4
|
|
|
5
|
-
const root = resolve(dirname(fileURLToPath(import.meta.url)), "
|
|
5
|
+
const root = resolve(dirname(fileURLToPath(import.meta.url)), "../..");
|
|
6
6
|
|
|
7
7
|
/** Resolve outside dependency shims, including PATH injected by bun run/install. */
|
|
8
8
|
export function discoverInstalledOmp(path = process.env.PATH ?? ""): string {
|
|
@@ -2,7 +2,7 @@ import type { Settings } from "@oh-my-pi/pi-coding-agent/config/settings";
|
|
|
2
2
|
import { Type, type Static } from "@sinclair/typebox";
|
|
3
3
|
import { IsStandardObject as isRecord, Value } from "@sinclair/typebox/value";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
|
-
import { credentialEnvNames, type Config } from "
|
|
5
|
+
import { credentialEnvNames, type Config } from "../config/config";
|
|
6
6
|
|
|
7
7
|
const nativeScope = {
|
|
8
8
|
source: Type.Union([Type.Literal("default"), Type.Literal("global"), Type.Literal("project"),
|
|
@@ -116,7 +116,7 @@ export function applyConsentedMnemopi(config: Config, consent: GlobalMemoryCandi
|
|
|
116
116
|
async function runMemoryHelper(config: Config, consent?: GlobalMemoryCandidate): Promise<ManagedMemoryReport> {
|
|
117
117
|
const env = { ...process.env };
|
|
118
118
|
for (const name of credentialEnvNames(config)) delete env[name];
|
|
119
|
-
const helper = fileURLToPath(new URL("
|
|
119
|
+
const helper = fileURLToPath(new URL("../managed-memory-helper.ts", import.meta.url));
|
|
120
120
|
const unavailable: ManagedMemoryReport = { memory: { status: "unknown" }, updated: false };
|
|
121
121
|
try {
|
|
122
122
|
const operation = consent ? "apply-consented" : "inspect";
|
|
@@ -3,9 +3,10 @@ import { lstatSync, readFileSync, realpathSync } from "node:fs";
|
|
|
3
3
|
import { chmod, link, lstat, mkdir, mkdtemp, readFile, readdir, realpath, rename, rm, writeFile } from "node:fs/promises";
|
|
4
4
|
import { dirname, isAbsolute, join, resolve, sep } from "node:path";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
|
-
import type { WorkerHostProfile } from "
|
|
6
|
+
import type { WorkerHostProfile } from "../worker/worker-profile";
|
|
7
|
+
import type { NativeProfile, NativeProfileBinding, NativeProfilePaths } from "./native-sessions";
|
|
7
8
|
|
|
8
|
-
const projectRoot = fileURLToPath(new URL("
|
|
9
|
+
const projectRoot = fileURLToPath(new URL("../../", import.meta.url));
|
|
9
10
|
const ownership = "omp-superagent-managed-ulw-v1";
|
|
10
11
|
const hash = /^[0-9a-f]{40,64}$/;
|
|
11
12
|
export const MANAGED_ULW_ENV = "OMP_SUPERAGENT_MANAGED_ULW_PATH";
|
|
@@ -53,7 +54,7 @@ function matchesUlwRepository(previous: string, current: string): boolean {
|
|
|
53
54
|
);
|
|
54
55
|
}
|
|
55
56
|
|
|
56
|
-
export function readUlwManifest(manifestPath = join(projectRoot, "upstream/
|
|
57
|
+
export function readUlwManifest(manifestPath = join(projectRoot, "upstream/super.json")): UlwManifest {
|
|
57
58
|
const value = JSON.parse(readFileSync(manifestPath, "utf8")) as UlwManifest;
|
|
58
59
|
if (!value.repository || value.ref !== "HEAD" || !value.directory ||
|
|
59
60
|
!Number.isSafeInteger(value.checkIntervalMs) || value.checkIntervalMs < 60_000 ||
|
|
@@ -185,7 +186,7 @@ async function probe(packagePath: string, stage: string, manifest: UlwManifest):
|
|
|
185
186
|
PI_CODING_AGENT_DIR: join(home, "agent"), XDG_CONFIG_HOME: join(home, "config"),
|
|
186
187
|
XDG_DATA_HOME: join(home, "data"), XDG_CACHE_HOME: join(home, "cache"), CI: "true", NO_COLOR: "1" };
|
|
187
188
|
if (process.env.PI_NATIVES_DIR) env.PI_NATIVES_DIR = process.env.PI_NATIVES_DIR;
|
|
188
|
-
await run([process.execPath, fileURLToPath(new URL("
|
|
189
|
+
await run([process.execPath, fileURLToPath(new URL("../managed-super-probe.ts", import.meta.url)), packagePath],
|
|
189
190
|
home, manifest.probeTimeoutMs, env);
|
|
190
191
|
}
|
|
191
192
|
|
|
@@ -200,6 +201,7 @@ export type ManagedUlwLaunchInput = {
|
|
|
200
201
|
/** Exact native OMP argv, including the original command's flags and generated Host args; no executable prefix. */
|
|
201
202
|
launchArgs: string[];
|
|
202
203
|
worker?: Pick<WorkerHostProfile, "extensionPaths">;
|
|
204
|
+
expectedNativeProfile?: NativeProfile;
|
|
203
205
|
};
|
|
204
206
|
type ManagedUlwLaunchOptions = Omit<ManagedUlwLaunchInput, "managedUlwPath"> & {
|
|
205
207
|
managedUlwPath?: string;
|
|
@@ -207,7 +209,14 @@ type ManagedUlwLaunchOptions = Omit<ManagedUlwLaunchInput, "managedUlwPath"> & {
|
|
|
207
209
|
bunCommand: string[];
|
|
208
210
|
discoveryTimeoutMs?: number;
|
|
209
211
|
};
|
|
210
|
-
export type ManagedUlwLaunchComposition = {
|
|
212
|
+
export type ManagedUlwLaunchComposition = {
|
|
213
|
+
extensionPaths: string[];
|
|
214
|
+
noExtensions: boolean;
|
|
215
|
+
memoryWriteDir: string | null;
|
|
216
|
+
nativeProfile?: NativeProfile;
|
|
217
|
+
nativeProfilePaths?: NativeProfilePaths;
|
|
218
|
+
nativeDotenvPaths?: string[];
|
|
219
|
+
};
|
|
211
220
|
|
|
212
221
|
const LAUNCH_DISCOVERY_TIMEOUT_MS = 30_000;
|
|
213
222
|
const LAUNCH_OUTPUT_LIMIT = 16 * 1024 * 1024; // Same bound as the Rust Gateway.
|
|
@@ -255,7 +264,7 @@ export async function managedUlwLaunch(options: ManagedUlwLaunchOptions, prepare
|
|
|
255
264
|
}): Promise<{ composition: ManagedUlwLaunchComposition; prepared?: string; deadline?: number }> {
|
|
256
265
|
if (!options.bunCommand.length) throw new Error("Managed ULW discovery requires the launcher's Bun command");
|
|
257
266
|
const { env, bunCommand, discoveryTimeoutMs = LAUNCH_DISCOVERY_TIMEOUT_MS, ...input } = options;
|
|
258
|
-
const helper = fileURLToPath(new URL("
|
|
267
|
+
const helper = fileURLToPath(new URL("../host-sdk-helper.ts", import.meta.url));
|
|
259
268
|
const child = Bun.spawn([...bunCommand, ...(input.worker ? ["--no-install"] : []), helper, "launch"], {
|
|
260
269
|
cwd: input.worker ? dirname(options.configPath) : options.cwd,
|
|
261
270
|
env: Object.fromEntries(Object.entries(env).filter((entry): entry is [string, string] => entry[1] !== undefined)),
|
|
@@ -337,7 +346,7 @@ export async function managedUlwLaunchComposition(input: ManagedUlwLaunchInput):
|
|
|
337
346
|
}
|
|
338
347
|
|
|
339
348
|
async function workerLaunchComposition(input: ManagedUlwLaunchInput & { worker: Pick<WorkerHostProfile, "extensionPaths"> }): Promise<ManagedUlwLaunchComposition> {
|
|
340
|
-
const { assertWorkerWorkspaceStartup } = await import("
|
|
349
|
+
const { assertWorkerWorkspaceStartup } = await import("../worker/worker-profile");
|
|
341
350
|
const { homedir } = await import("node:os");
|
|
342
351
|
assertWorkerWorkspaceStartup(input.cwd, homedir());
|
|
343
352
|
const { parseNativeLaunch } = await import("./native-launch-profile");
|
|
@@ -380,19 +389,31 @@ async function launchComposition(input: ManagedUlwLaunchInput): Promise<ManagedU
|
|
|
380
389
|
const { discoverCustomCommands } = await import("@oh-my-pi/pi-coding-agent/extensibility/custom-commands/loader");
|
|
381
390
|
const { getAgentDir } = await import("@oh-my-pi/pi-utils");
|
|
382
391
|
const { homedir } = await import("node:os");
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
const
|
|
386
|
-
const
|
|
387
|
-
|
|
392
|
+
const { matchesNativeProfile, resolveNativeProfile, sdkNativeProfilePaths } = await import("./native-sessions");
|
|
393
|
+
const nativeProfilePaths = sdkNativeProfilePaths(getAgentDir());
|
|
394
|
+
const nativeProfile = resolveNativeProfile(nativeProfilePaths);
|
|
395
|
+
const roots = { nativeProfile, nativeProfilePaths, nativeDotenvPaths: parsed.nativeDotenvPaths };
|
|
396
|
+
if (input.expectedNativeProfile && !matchesNativeProfile(nativeProfilePaths, input.expectedNativeProfile)) {
|
|
397
|
+
// The Gateway consumes the observed roots to fence this wake before it
|
|
398
|
+
// offers a preparation manifest or permits native memory fallback writes.
|
|
399
|
+
return { extensionPaths: [], noExtensions: true, memoryWriteDir: null, ...roots };
|
|
400
|
+
}
|
|
388
401
|
let memoryWriteDir: string | null = parsed.launchAgentDir;
|
|
389
402
|
if (input.parentConfigPath) {
|
|
390
403
|
// A lane inherits its head's post-dotenv environment. It cannot use that
|
|
391
404
|
// environment to enlarge the write authority recorded by the head's launcher.
|
|
392
|
-
const parent:
|
|
393
|
-
|
|
394
|
-
|
|
405
|
+
const parent: { configPath?: string; memoryWriteDir?: string; nativeProfileBinding?: NativeProfileBinding } | null =
|
|
406
|
+
await Bun.file(join(dirname(input.parentConfigPath), "owner.json")).json().catch(() => null);
|
|
407
|
+
if (parent?.configPath !== input.parentConfigPath || parent.memoryWriteDir !== memoryWriteDir) memoryWriteDir = null;
|
|
408
|
+
if (parent?.configPath === input.parentConfigPath && parent.nativeProfileBinding &&
|
|
409
|
+
!matchesNativeProfile(nativeProfilePaths, parent.nativeProfileBinding.profile))
|
|
410
|
+
throw new Error("Native lane discovery profile differs from its managed HEAD");
|
|
395
411
|
}
|
|
412
|
+
if (parsed.pluginDirs?.length) await injectPluginDirRoots(homedir(), parsed.pluginDirs, cwd);
|
|
413
|
+
else await preloadPluginRoots(homedir(), cwd);
|
|
414
|
+
const { ensureManagedMemory, memoryBlockReason } = await import("./managed-memory");
|
|
415
|
+
const settings = await Settings.loadReadOnly({ cwd, agentDir: getAgentDir(), configFiles: parsed.config })
|
|
416
|
+
.catch(() => { throw new Error(memoryBlockReason({ status: "unknown" })); });
|
|
396
417
|
let composition: { extensionPaths: string[]; noExtensions: boolean };
|
|
397
418
|
const restore = initializeWithSettings(settings);
|
|
398
419
|
try {
|
|
@@ -510,9 +531,14 @@ async function launchComposition(input: ManagedUlwLaunchInput): Promise<ManagedU
|
|
|
510
531
|
// Discovery can refuse an incompatible launch. Do not persist memory for it.
|
|
511
532
|
const { readNativeSettings } = await import("./native-settings");
|
|
512
533
|
const current = await readNativeSettings(settings).catch(() => { throw new Error(memoryBlockReason({ status: "unknown" })); });
|
|
534
|
+
if (!matchesNativeProfile(sdkNativeProfilePaths(current.getAgentDir()), nativeProfile))
|
|
535
|
+
throw new Error("Native profile changed during launch discovery");
|
|
513
536
|
const { memory } = await ensureManagedMemory(current, memoryWriteDir);
|
|
514
537
|
if (memory.status !== "enabled") throw new Error(memoryBlockReason(memory));
|
|
515
|
-
|
|
538
|
+
// Recheck the earlier observation before handing off to journal preparation.
|
|
539
|
+
if (!matchesNativeProfile(sdkNativeProfilePaths(settings.getAgentDir()), nativeProfile))
|
|
540
|
+
throw new Error("Native profile changed during launch discovery");
|
|
541
|
+
return { ...composition, memoryWriteDir, ...roots };
|
|
516
542
|
}
|
|
517
543
|
|
|
518
544
|
/** Serialized source preparation only. No Gateway, account adapter, or Host starts here. */
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { constants, type Stats } from "node:fs";
|
|
2
|
+
import { open, stat, type FileHandle } from "node:fs/promises";
|
|
3
|
+
|
|
4
|
+
// OMP 19.2.1 docs/session.md: JSONL with an optional initial title slot.
|
|
5
|
+
// Older versions share the header identity; native resume owns migrations.
|
|
6
|
+
const HEADER_LIMIT = 1024 * 1024;
|
|
7
|
+
const CHUNK_BYTES = 16 * 1024;
|
|
8
|
+
const utf8 = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
|
|
9
|
+
|
|
10
|
+
type Entry = Readonly<Record<string, unknown>> & { readonly type: string };
|
|
11
|
+
type FileIdentity = Pick<Stats, "dev" | "ino">;
|
|
12
|
+
type Journal = { readonly file: FileHandle; readonly initial: Stats };
|
|
13
|
+
|
|
14
|
+
export class NativeJournalFormatError extends Error {
|
|
15
|
+
constructor() { super("Unrecognized or incomplete native session journal"); }
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function sameFile(left: FileIdentity, right: FileIdentity): boolean {
|
|
19
|
+
return left.ino === right.ino && left.dev === right.dev;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async function openJournal(path: string, expected?: FileIdentity): Promise<Journal | undefined> {
|
|
23
|
+
let file: FileHandle;
|
|
24
|
+
try {
|
|
25
|
+
file = await open(path, constants.O_RDONLY | constants.O_NONBLOCK | (expected ? constants.O_NOFOLLOW : 0));
|
|
26
|
+
} catch (error) {
|
|
27
|
+
if (error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR"))
|
|
28
|
+
return undefined;
|
|
29
|
+
throw error;
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
const initial = await file.stat();
|
|
33
|
+
if (!initial.isFile() || expected && !sameFile(initial, expected)) throw new NativeJournalFormatError();
|
|
34
|
+
return { file, initial };
|
|
35
|
+
} catch (error) {
|
|
36
|
+
await file.close();
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function isEntry(value: unknown): value is Entry {
|
|
42
|
+
return typeof value === "object" && value !== null && !Array.isArray(value)
|
|
43
|
+
&& "type" in value && typeof value.type === "string";
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function titleSlot(entry: Entry): boolean {
|
|
47
|
+
return entry.type === "title" && entry.v === 1 && typeof entry.title === "string"
|
|
48
|
+
&& typeof entry.updatedAt === "string" && typeof entry.pad === "string"
|
|
49
|
+
&& (entry.source === undefined || entry.source === "auto" || entry.source === "user");
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Only a complete title record on the first physical line is outside the journal. */
|
|
53
|
+
function titleSlotEnd(prefix: Buffer): number {
|
|
54
|
+
const lf = prefix.indexOf(0x0a);
|
|
55
|
+
if (lf < 0) return 0;
|
|
56
|
+
try {
|
|
57
|
+
const entry: unknown = JSON.parse(utf8.decode(prefix.subarray(0, lf)).trim());
|
|
58
|
+
return isEntry(entry) && titleSlot(entry) ? lf + 1 : 0;
|
|
59
|
+
} catch (error) {
|
|
60
|
+
if (error instanceof SyntaxError || error instanceof TypeError) return 0;
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function headerId(prefix: Buffer): string | undefined {
|
|
66
|
+
// Stock trims the physical title line, but skips only JSON whitespace
|
|
67
|
+
// before a header. In particular, a BOM is not a header prefix.
|
|
68
|
+
let start = titleSlotEnd(prefix);
|
|
69
|
+
while (start < prefix.length) {
|
|
70
|
+
const byte = prefix[start];
|
|
71
|
+
if (byte !== 0x20 && byte !== 0x09 && byte !== 0x0a && byte !== 0x0d) break;
|
|
72
|
+
start++;
|
|
73
|
+
}
|
|
74
|
+
if (prefix[start] !== 0x7b) return undefined;
|
|
75
|
+
|
|
76
|
+
// A header can span lines. Decode through its closing brace, not the body.
|
|
77
|
+
let depth = 0;
|
|
78
|
+
let quoted = false;
|
|
79
|
+
for (let i = start; i < prefix.length; i++) {
|
|
80
|
+
const byte = prefix[i];
|
|
81
|
+
if (quoted && byte === 0x5c) { i++; continue; } // escaped byte inside a string
|
|
82
|
+
if (byte === 0x22) quoted = !quoted;
|
|
83
|
+
if (quoted) continue;
|
|
84
|
+
if (byte === 0x7b) depth++;
|
|
85
|
+
if (byte !== 0x7d) continue;
|
|
86
|
+
depth--;
|
|
87
|
+
if (depth !== 0) continue;
|
|
88
|
+
try {
|
|
89
|
+
const entry: unknown = JSON.parse(utf8.decode(prefix.subarray(start, i + 1)));
|
|
90
|
+
if (isEntry(entry) && entry.type === "session" && typeof entry.id === "string" && entry.id) return entry.id;
|
|
91
|
+
// A complete title object can still be waiting for its physical newline.
|
|
92
|
+
return undefined;
|
|
93
|
+
} catch (error) {
|
|
94
|
+
if (!(error instanceof SyntaxError || error instanceof TypeError)) throw error;
|
|
95
|
+
}
|
|
96
|
+
throw new NativeJournalFormatError();
|
|
97
|
+
}
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Read a bounded identity prefix. Only a missing path is reported as absent. */
|
|
102
|
+
export async function readNativeSessionId(path: string, expected?: FileIdentity): Promise<string | undefined> {
|
|
103
|
+
const journal = await openJournal(path, expected);
|
|
104
|
+
if (!journal) return undefined;
|
|
105
|
+
try {
|
|
106
|
+
const limit = Math.min(journal.initial.size, HEADER_LIMIT);
|
|
107
|
+
let prefix = Buffer.alloc(0);
|
|
108
|
+
while (prefix.length < limit) {
|
|
109
|
+
const remaining = Math.min(limit - prefix.length, Math.max(CHUNK_BYTES, prefix.length));
|
|
110
|
+
const chunk = Buffer.allocUnsafe(remaining);
|
|
111
|
+
const { bytesRead } = await journal.file.read(chunk, 0, remaining, prefix.length);
|
|
112
|
+
if (!bytesRead) break;
|
|
113
|
+
const read = chunk.subarray(0, bytesRead);
|
|
114
|
+
prefix = prefix.length ? Buffer.concat([prefix, read]) : read;
|
|
115
|
+
const id = headerId(prefix);
|
|
116
|
+
if (id !== undefined) {
|
|
117
|
+
if (!sameFile(journal.initial, await stat(path))) throw new NativeJournalFormatError();
|
|
118
|
+
return id;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
throw new NativeJournalFormatError();
|
|
122
|
+
} finally { await journal.file.close(); }
|
|
123
|
+
}
|
|
124
|
+
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
+
import { homedir } from "node:os";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
|
|
1
4
|
/** Stock OMP chooses its profile before settings or discovery import native dotenv. */
|
|
2
5
|
export async function parseNativeLaunch(launchArgs: readonly string[]) {
|
|
3
6
|
const { extractProfileFlags } = await import("@oh-my-pi/pi-coding-agent/cli/profile-bootstrap");
|
|
4
|
-
const { getAgentDir, setProfile, resolveProfileEnv } = await import("@oh-my-pi/pi-utils/dirs");
|
|
7
|
+
const { getAgentDir, getConfigRootDir, getProjectDir, setProfile, resolveProfileEnv } = await import("@oh-my-pi/pi-utils/dirs");
|
|
5
8
|
const bootstrap = extractProfileFlags(launchArgs);
|
|
6
9
|
setProfile(bootstrap.profile ?? resolveProfileEnv(process.env.OMP_PROFILE, process.env.PI_PROFILE));
|
|
7
10
|
// Capture the operator's destination before native launch imports load workspace dotenv.
|
|
8
11
|
const launchAgentDir = getAgentDir();
|
|
12
|
+
const nativeDotenvPaths = [getProjectDir(), launchAgentDir, getConfigRootDir(), homedir()].map(dir => join(dir, ".env"));
|
|
9
13
|
if (bootstrap.aliasName !== undefined) throw new Error("Managed Hosts cannot install native aliases");
|
|
10
14
|
const { isNativeShell } = await import("@oh-my-pi/pi-coding-agent/cli/native-shell");
|
|
11
15
|
if (isNativeShell(bootstrap.argv[0])) throw new Error("Managed Hosts require native launch argv, not a shell command");
|
|
@@ -14,5 +18,5 @@ export async function parseNativeLaunch(launchArgs: readonly string[]) {
|
|
|
14
18
|
if ("error" in resolved) throw new Error(resolved.error);
|
|
15
19
|
if (resolved.argv[0] !== "launch") throw new Error("Managed Hosts require native OMP launch argv");
|
|
16
20
|
const { parseArgs } = await import("@oh-my-pi/pi-coding-agent/cli/args");
|
|
17
|
-
return { ...parseArgs(resolved.argv.slice(1)), launchAgentDir };
|
|
21
|
+
return { ...parseArgs(resolved.argv.slice(1)), launchAgentDir, nativeDotenvPaths };
|
|
18
22
|
}
|
|
@@ -7,8 +7,8 @@ import { acquireModelRoleMutation, getModelPreset, getModelPresetNames, isValidM
|
|
|
7
7
|
import { pickDefaultAvailableModel, resolveModelRoleValue } from "@oh-my-pi/pi-coding-agent/config/model-resolver";
|
|
8
8
|
import type { Settings, SettingsMirrorState } from "@oh-my-pi/pi-coding-agent/config/settings";
|
|
9
9
|
import { cfgDefaultThinkingLevel } from "@oh-my-pi/pi-coding-agent/session/settings";
|
|
10
|
-
import { MODEL_PRESET_NAMES, type LaneModel, type LanePresetSnapshot, type ResolvedLanePreset, type StorePort } from "
|
|
11
|
-
import { isLaneModel, sameLaneModel } from "
|
|
10
|
+
import { MODEL_PRESET_NAMES, type LaneModel, type LanePresetSnapshot, type ResolvedLanePreset, type StorePort } from "../contracts";
|
|
11
|
+
import { isLaneModel, sameLaneModel } from "../lane/lane-models";
|
|
12
12
|
import { editNativeGlobalConfig, hasUnresolvedNativeLegacy, readNativeSettings } from "./native-settings";
|
|
13
13
|
|
|
14
14
|
export type NativeModel = Awaited<ReturnType<ExtensionContext["models"]["list"]>>[number];
|