omp-superagent 0.1.8 → 0.1.10
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 +16 -8
- package/README.ko.md +28 -374
- package/README.md +30 -421
- package/THIRD_PARTY_NOTICES.md +8 -8
- package/config.example.json +7 -0
- package/docs/OPERATIONS.en.md +2223 -0
- package/docs/OPERATIONS.md +164 -23
- package/docs/design/execution.md +164 -18
- package/docs/design/messaging.md +78 -17
- package/docs/kakao-bridge-protocol.md +193 -0
- package/docs/releases/0.1.10.md +17 -0
- package/docs/releases/0.1.9.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/notices/darwin-arm64/Cargo-LICENSES.txt +2 -0
- package/host-owner/bin/notices/darwin-arm64/Cargo-SOURCES.txt +2 -0
- package/host-owner/bin/notices/darwin-arm64/crates/bitflags-2.13.2/LICENSE-APACHE +201 -0
- package/host-owner/bin/notices/darwin-arm64/crates/bitflags-2.13.2/LICENSE-MIT +25 -0
- package/host-owner/bin/notices/darwin-arm64/crates/rustix-1.1.6/COPYRIGHT +29 -0
- package/host-owner/bin/notices/darwin-arm64/crates/rustix-1.1.6/LICENSE-APACHE +201 -0
- package/host-owner/bin/notices/darwin-arm64/crates/rustix-1.1.6/LICENSE-Apache-2.0_WITH_LLVM-exception +220 -0
- package/host-owner/bin/notices/darwin-arm64/crates/rustix-1.1.6/LICENSE-MIT +23 -0
- package/host-owner/bin/notices/darwin-x64/Cargo-LICENSES.txt +2 -0
- package/host-owner/bin/notices/darwin-x64/Cargo-SOURCES.txt +2 -0
- package/host-owner/bin/notices/darwin-x64/crates/bitflags-2.13.2/LICENSE-APACHE +201 -0
- package/host-owner/bin/notices/darwin-x64/crates/bitflags-2.13.2/LICENSE-MIT +25 -0
- package/host-owner/bin/notices/darwin-x64/crates/rustix-1.1.6/COPYRIGHT +29 -0
- package/host-owner/bin/notices/darwin-x64/crates/rustix-1.1.6/LICENSE-APACHE +201 -0
- package/host-owner/bin/notices/darwin-x64/crates/rustix-1.1.6/LICENSE-Apache-2.0_WITH_LLVM-exception +220 -0
- package/host-owner/bin/notices/darwin-x64/crates/rustix-1.1.6/LICENSE-MIT +23 -0
- package/host-owner/bin/notices/linux-arm64/Cargo-LICENSES.txt +3 -0
- package/host-owner/bin/notices/linux-arm64/Cargo-SOURCES.txt +3 -0
- package/host-owner/bin/notices/linux-arm64/crates/bitflags-2.13.2/LICENSE-APACHE +201 -0
- package/host-owner/bin/notices/linux-arm64/crates/bitflags-2.13.2/LICENSE-MIT +25 -0
- package/host-owner/bin/notices/linux-arm64/crates/linux-raw-sys-0.12.1/COPYRIGHT +29 -0
- package/host-owner/bin/notices/linux-arm64/crates/linux-raw-sys-0.12.1/LICENSE-APACHE +201 -0
- package/host-owner/bin/notices/linux-arm64/crates/linux-raw-sys-0.12.1/LICENSE-Apache-2.0_WITH_LLVM-exception +220 -0
- package/host-owner/bin/notices/linux-arm64/crates/linux-raw-sys-0.12.1/LICENSE-MIT +23 -0
- package/host-owner/bin/notices/linux-arm64/crates/rustix-1.1.6/COPYRIGHT +29 -0
- package/host-owner/bin/notices/linux-arm64/crates/rustix-1.1.6/LICENSE-APACHE +201 -0
- package/host-owner/bin/notices/linux-arm64/crates/rustix-1.1.6/LICENSE-Apache-2.0_WITH_LLVM-exception +220 -0
- package/host-owner/bin/notices/linux-arm64/crates/rustix-1.1.6/LICENSE-MIT +23 -0
- package/host-owner/bin/notices/linux-x64/Cargo-LICENSES.txt +3 -0
- package/host-owner/bin/notices/linux-x64/Cargo-SOURCES.txt +3 -0
- package/host-owner/bin/notices/linux-x64/crates/bitflags-2.13.2/LICENSE-APACHE +201 -0
- package/host-owner/bin/notices/linux-x64/crates/bitflags-2.13.2/LICENSE-MIT +25 -0
- package/host-owner/bin/notices/linux-x64/crates/linux-raw-sys-0.12.1/COPYRIGHT +29 -0
- package/host-owner/bin/notices/linux-x64/crates/linux-raw-sys-0.12.1/LICENSE-APACHE +201 -0
- package/host-owner/bin/notices/linux-x64/crates/linux-raw-sys-0.12.1/LICENSE-Apache-2.0_WITH_LLVM-exception +220 -0
- package/host-owner/bin/notices/linux-x64/crates/linux-raw-sys-0.12.1/LICENSE-MIT +23 -0
- package/host-owner/bin/notices/linux-x64/crates/rustix-1.1.6/COPYRIGHT +29 -0
- package/host-owner/bin/notices/linux-x64/crates/rustix-1.1.6/LICENSE-APACHE +201 -0
- package/host-owner/bin/notices/linux-x64/crates/rustix-1.1.6/LICENSE-Apache-2.0_WITH_LLVM-exception +220 -0
- package/host-owner/bin/notices/linux-x64/crates/rustix-1.1.6/LICENSE-MIT +23 -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 -8
- package/skills/head/SKILL.md +28 -14
- package/skills/head/references/routing.md +23 -17
- package/skills/head/references/supervision.md +22 -1
- package/skills/lane/SKILL.md +11 -0
- package/skills/lane/references/workflow.md +17 -8
- package/src/cli.ts +6 -4
- package/src/config.ts +44 -3
- package/src/contracts.ts +101 -8
- package/src/discord-command-registration.ts +34 -186
- package/src/extension.ts +44 -6
- package/src/gateway-client.ts +11 -59
- package/src/gateway-protocol.ts +35 -1
- package/src/head-recovery.ts +226 -17
- package/src/host-extension.ts +132 -17
- package/src/host-protocol.ts +6 -9
- package/src/host-reply-voice.ts +181 -0
- package/src/lane-extension.ts +46 -8
- package/src/lane-models.ts +8 -0
- package/src/lane-report.ts +22 -0
- package/src/managed-ulw-probe.ts +22 -20
- package/src/message-order.ts +2 -1
- package/src/messenger-command-catalog.json +6 -3
- package/src/messenger-commands.ts +9 -2
- package/src/operator.ts +77 -0
- package/src/pr-github-schema.ts +2 -0
- package/src/pr-intake-automation.ts +1 -2
- package/src/pr-intake-comment.ts +1 -2
- package/src/pr-intake-fix.ts +1 -2
- package/src/pr-intake-github.ts +1 -2
- package/src/pr-intake-material.ts +1 -2
- package/src/pr-intake-tree.ts +1 -2
- package/src/pr-review-models.ts +28 -0
- package/src/result-attachment.ts +60 -79
- package/src/runtime.ts +1862 -298
- package/src/setup-profiles.ts +26 -65
- package/src/setup.ts +2 -1
- package/src/slack-command-registration.ts +48 -197
- package/src/soul.ts +214 -0
- package/src/store.ts +643 -55
- package/src/superkit-skills.ts +22 -0
- package/src/telegram-command-languages.json +17 -0
- package/src/telegram-command-registration.ts +32 -134
- package/src/worker-bridge.ts +21 -0
- package/src/worker-enrollment.ts +2 -1
- package/src/worker-host.ts +0 -24
- package/src/worker-serve-prepare.ts +19 -0
- package/src/worker-service.ts +51 -47
- package/scripts/ci.ts +0 -44
- package/scripts/release.ts +0 -112
- package/scripts/test-omp.sh +0 -44
- package/src/discord-commands.ts +0 -29
- package/src/discord-markdown.ts +0 -399
- package/src/slack-commands.ts +0 -18
- package/src/telegram-signal.ts +0 -14
- package/src/worker-stdio.ts +0 -61
package/src/host-extension.ts
CHANGED
|
@@ -8,10 +8,10 @@ import type { UnitScope } from "@oh-my-pi/pi-coding-agent/daemon/protocol";
|
|
|
8
8
|
import { cfgDefaultThinkingLevel } from "@oh-my-pi/pi-coding-agent/session/settings";
|
|
9
9
|
import { Settings } from "@oh-my-pi/pi-coding-agent/config/settings";
|
|
10
10
|
import { lookup as lookupSetting } from "@oh-my-pi/pi-coding-agent/config/registry";
|
|
11
|
-
import { pickDefaultAvailableModel, resolveModelRoleValue } from "@oh-my-pi/pi-coding-agent/config/model-resolver";
|
|
11
|
+
import { formatModelStringWithRouting, pickDefaultAvailableModel, resolveModelRoleValue } from "@oh-my-pi/pi-coding-agent/config/model-resolver";
|
|
12
12
|
import { resolveThinkingLevelForModel } from "@oh-my-pi/pi-tui/thinking";
|
|
13
13
|
import { parseSessionEntries, readSessionHeaderId } from "@oh-my-pi/pi-coding-agent/session/session-loader";
|
|
14
|
-
import { HostChannel, PR_REVIEW_GITHUB_ENV, PR_REVIEW_SYSTEM_PROMPT, indexServiceCompletions, serviceGenerationKey, type Frame, type ServiceUnit } from "./host-protocol";
|
|
14
|
+
import { HostChannel, LANE_MODEL_PROMOTION_RECEIPT, PR_REVIEW_GITHUB_ENV, PR_REVIEW_SYSTEM_PROMPT, indexServiceCompletions, serviceGenerationKey, type Frame, type ServiceUnit } from "./host-protocol";
|
|
15
15
|
import { USER_INTERRUPT_LABEL } from "@oh-my-pi/pi-coding-agent/session/messages";
|
|
16
16
|
import { MAX_RPC_REASSEMBLED_BYTES } from "@oh-my-pi/pi-coding-agent/modes/rpc/rpc-frame";
|
|
17
17
|
import { fitAbortAndRestoreQueueResponse } from "@oh-my-pi/pi-coding-agent/modes/rpc/rpc-mode";
|
|
@@ -21,8 +21,10 @@ import { toolWireSchema } from "@oh-my-pi/pi-ai/utils/schema";
|
|
|
21
21
|
import type { LanePresetSnapshot } from "./contracts";
|
|
22
22
|
import { MANAGED_ULW_ENV } from "./managed-ulw";
|
|
23
23
|
import { verifyHostSuperkit } from "./host-superkit";
|
|
24
|
+
import { isPrReviewInferenceModel, prReviewModelChoices } from "./pr-review-models";
|
|
24
25
|
import { HEAD_ROTATION_GUARD, HEAD_ROTATION_PROBE, type RotationGuardEvent,
|
|
25
26
|
type RotationNative, type RotationProbeEvent } from "./head-rotation";
|
|
27
|
+
import { installReplyVoice } from "./host-reply-voice";
|
|
26
28
|
|
|
27
29
|
const terminalService = (state: ServiceUnit["state"]) => state === "exited" || state === "failed";
|
|
28
30
|
const serviceGeneration = ({ owner, id, generation, startedAt, restartCount }: ServiceUnit) =>
|
|
@@ -33,8 +35,6 @@ const serviceOwner = ({ agent, sessionManager }: ExtensionContext) => {
|
|
|
33
35
|
return agent.kind === "sub" && agent.id === "advisor" ? `${id}-advisor` : id;
|
|
34
36
|
};
|
|
35
37
|
|
|
36
|
-
const reviewInferenceApis = new Set(["openai-completions", "openai-responses", "openai-codex-responses",
|
|
37
|
-
"azure-openai-responses", "anthropic-messages"]);
|
|
38
38
|
const stockAutoresearchTools = ["init_experiment", "run_experiment", "log_experiment", "update_notes"] as const;
|
|
39
39
|
// --no-tools can still leave builtins in the registration catalogue: write
|
|
40
40
|
// on stock 19.0, resolution/QA devices on 19.1. None may be enabled, mounted,
|
|
@@ -47,9 +47,8 @@ const reviewSettingValues = {
|
|
|
47
47
|
"prewalk.auto": "off", "spotlight.experiment.enabled": false, "providers.cacheWarming": "off", "telemetry.otlpExportEnabled": false,
|
|
48
48
|
"dev.autoqa": false,
|
|
49
49
|
} as const;
|
|
50
|
-
const reviewModelAllowed = (model: { api: string; provider: string; transport?: unknown } | undefined) =>
|
|
51
|
-
model !== undefined && reviewInferenceApis.has(model.api) && model.provider !== "gitlab-duo" && model.transport !== "pi-native";
|
|
52
50
|
class ReviewIsolationError extends Error {}
|
|
51
|
+
class DescendantOwnershipChanged extends Error {}
|
|
53
52
|
|
|
54
53
|
/** Match the running CLI's own RPC settlement predicate (old and new SDK surface). */
|
|
55
54
|
function pendingNativeWake(session: { readonly wakeSources?: unknown; readonly hasPendingAsyncWork?: () => boolean }): boolean {
|
|
@@ -85,6 +84,7 @@ export default function hostExtension(pi: ExtensionAPI): void {
|
|
|
85
84
|
const selectedSuperkit = process.env[MANAGED_ULW_ENV];
|
|
86
85
|
const workerAttempt = process.env.OMP_SUPERAGENT_WORKER_ATTEMPT;
|
|
87
86
|
const reviewCwd = process.env.OMP_SUPERAGENT_PR_REVIEW_CWD;
|
|
87
|
+
let replyVoice: ReturnType<typeof installReplyVoice>;
|
|
88
88
|
if (reviewCwd && PR_REVIEW_GITHUB_ENV.some(name => process.env[name]))
|
|
89
89
|
throw new Error("Static PR review cannot load GitHub credentials from the native profile");
|
|
90
90
|
let loadedSuperkitPath: string | undefined;
|
|
@@ -100,6 +100,25 @@ export default function hostExtension(pi: ExtensionAPI): void {
|
|
|
100
100
|
if (!(root instanceof pi.pi.AgentSession)) throw new Error("Native root session is unavailable");
|
|
101
101
|
return root;
|
|
102
102
|
};
|
|
103
|
+
const flushLaneModel = (session: ReturnType<typeof rootSession>, previousLeaf: string | null, promoting: boolean) => {
|
|
104
|
+
const journal = session.sessionManager;
|
|
105
|
+
const model = session.model;
|
|
106
|
+
const branch = journal.getBranch();
|
|
107
|
+
const previousIndex = previousLeaf === null ? -1 : branch.findIndex(entry => entry.id === previousLeaf);
|
|
108
|
+
const modelIndex = branch.findLastIndex(entry => entry.type === "model_change" && (entry.role ?? "default") === "default");
|
|
109
|
+
const change = branch[modelIndex];
|
|
110
|
+
if (!model || (previousLeaf !== null && previousIndex === -1) || modelIndex <= previousIndex
|
|
111
|
+
|| change?.type !== "model_change" || change.resolvedModelIsFallback === true
|
|
112
|
+
|| change.model !== formatModelStringWithRouting(model))
|
|
113
|
+
throw new Error("Lane model journal selection could not be confirmed");
|
|
114
|
+
if (promoting) {
|
|
115
|
+
// The stock selector may flatten distinct provider/ID pairs.
|
|
116
|
+
journal.appendCustomEntry(LANE_MODEL_PROMOTION_RECEIPT, {
|
|
117
|
+
entryId: change.id, selector: change.model, model: { provider: model.provider, id: model.id },
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
journal.flushSync();
|
|
121
|
+
};
|
|
103
122
|
const serviceObservation = (data: Frame) => {
|
|
104
123
|
const root = rootSession();
|
|
105
124
|
root.sessionManager.appendCustomEntry("superagent_service_generation", {
|
|
@@ -171,7 +190,7 @@ export default function hostExtension(pi: ExtensionAPI): void {
|
|
|
171
190
|
let reviewStream: NativeSession["agent"]["streamFn"] | undefined;
|
|
172
191
|
const reviewPolicy = (session: NativeSession, cwd: string) => {
|
|
173
192
|
const model = session.model;
|
|
174
|
-
if (!
|
|
193
|
+
if (!model || !isPrReviewInferenceModel(model))
|
|
175
194
|
throw new ReviewIsolationError("Static PR review requires a known tool-less inference API, not an external agent harness");
|
|
176
195
|
if (workerAttempt || realpathSync(session.sessionManager.getCwd()) !== cwd)
|
|
177
196
|
throw new ReviewIsolationError("Static PR review workspace identity is unavailable");
|
|
@@ -224,12 +243,12 @@ export default function hostExtension(pi: ExtensionAPI): void {
|
|
|
224
243
|
reviewPolicy(session, cwd);
|
|
225
244
|
// The actual candidate can differ from the selection on provider retry.
|
|
226
245
|
// Reject it before native dispatch, rather than trusting provider naming.
|
|
227
|
-
if (!
|
|
246
|
+
if (!isPrReviewInferenceModel(model) || input.tools?.length || input.inactiveTools?.length)
|
|
228
247
|
throw new Error("Static PR review refused a tool-capable provider request");
|
|
229
248
|
const checkedPayload: NonNullable<NonNullable<typeof options>["onPayload"]> = async (payload, current, signal) => {
|
|
230
249
|
const replacement = await options?.onPayload?.(payload, current, signal);
|
|
231
250
|
const outgoing = replacement ?? payload;
|
|
232
|
-
if (!
|
|
251
|
+
if (!isPrReviewInferenceModel(current ?? model) || !outgoing || typeof outgoing !== "object"
|
|
233
252
|
|| ["tools", "functions", "mcp_servers"].some(key => {
|
|
234
253
|
const value = Object.getOwnPropertyDescriptor(outgoing, key)?.value;
|
|
235
254
|
return value !== undefined && (!Array.isArray(value) || value.length !== 0);
|
|
@@ -262,8 +281,13 @@ export default function hostExtension(pi: ExtensionAPI): void {
|
|
|
262
281
|
return entry.id;
|
|
263
282
|
} catch (error) { observationHeld = true; throw error; }
|
|
264
283
|
};
|
|
265
|
-
const
|
|
266
|
-
const
|
|
284
|
+
const assertSameRoot = (identity: ReturnType<typeof exact>) => {
|
|
285
|
+
const current = exact();
|
|
286
|
+
if (current.ref !== identity.ref || current.session !== identity.session
|
|
287
|
+
|| current.id !== identity.id || current.file !== identity.file)
|
|
288
|
+
throw new Error("Native root changed during ownership observation");
|
|
289
|
+
};
|
|
290
|
+
const observeOwned = async (identity: ReturnType<typeof exact>, drain: boolean) => {
|
|
267
291
|
const registry = pi.pi.AgentRegistry.global();
|
|
268
292
|
const refs = registry.list();
|
|
269
293
|
const refEpoch = refs.map(ref => [ref.id, ref.generation, ref.parentId, ref.session?.instanceKey, ref.sessionFile]);
|
|
@@ -347,10 +371,10 @@ export default function hostExtension(pi: ExtensionAPI): void {
|
|
|
347
371
|
}
|
|
348
372
|
const scopedServices = async () => (await observeServices()).filter(unit => unit.owner && owners.has(unit.owner));
|
|
349
373
|
const services = await scopedServices();
|
|
374
|
+
assertSameRoot(identity);
|
|
350
375
|
const currentRefs = registry.list();
|
|
351
|
-
if (
|
|
352
|
-
|
|
353
|
-
throw new Error("Native ownership tree changed during service observation");
|
|
376
|
+
if (currentRefs.length !== refs.length || refs.some((ref, index) => currentRefs[index] !== ref))
|
|
377
|
+
throw new DescendantOwnershipChanged("Native ownership tree changed during service observation");
|
|
354
378
|
const deliveriesPending = (session: NativeSession) => {
|
|
355
379
|
const delivery = session.getAsyncJobSnapshot({ recentLimit: 0 })?.delivery;
|
|
356
380
|
return !!delivery && (delivery.delivering || delivery.queued > 0 || delivery.pendingJobIds.length > 0);
|
|
@@ -438,13 +462,28 @@ export default function hostExtension(pi: ExtensionAPI): void {
|
|
|
438
462
|
if (!isDeepStrictEqual(services, refreshed))
|
|
439
463
|
throw new Error("Native services changed while their durable completion evidence was drained");
|
|
440
464
|
}
|
|
465
|
+
assertSameRoot(identity);
|
|
441
466
|
if (!isDeepStrictEqual(refEpoch, registry.list().map(ref =>
|
|
442
467
|
[ref.id, ref.generation, ref.parentId, ref.session?.instanceKey, ref.sessionFile])))
|
|
443
|
-
throw new
|
|
468
|
+
throw new DescendantOwnershipChanged("Native descendant identity changed during completion readback");
|
|
444
469
|
const tree = identity.session.getAsyncJobTree({ recentLimit: 0 });
|
|
445
470
|
return { identity, tree, unknown: servicesUnknown || serviceDeliveryUnknown || descendantsUnknown(),
|
|
446
471
|
busy: liveGenerations.size > 0 || descendantsBusy() || deliveriesPending(identity.session) || !!tree?.running.length };
|
|
447
472
|
};
|
|
473
|
+
const owned = async (drain = false) => {
|
|
474
|
+
const identity = exact();
|
|
475
|
+
// Stock OMP registers a child before attaching its session. Each
|
|
476
|
+
// transition can invalidate a different read. Rebuild all evidence
|
|
477
|
+
// together, and never retry a maintenance drain.
|
|
478
|
+
for (let remaining = drain ? 0 : 2; ; remaining--) {
|
|
479
|
+
try {
|
|
480
|
+
return await observeOwned(identity, drain);
|
|
481
|
+
} catch (error) {
|
|
482
|
+
if (remaining === 0 || !(error instanceof DescendantOwnershipChanged)) throw error;
|
|
483
|
+
assertSameRoot(identity);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
};
|
|
448
487
|
const localIdle = () => {
|
|
449
488
|
const { session } = exact();
|
|
450
489
|
return !mutationHeld && !observationHeld && !session.isDisposed && !session.isBusyForSnapshot && !session.isStreaming
|
|
@@ -472,6 +511,14 @@ export default function hostExtension(pi: ExtensionAPI): void {
|
|
|
472
511
|
modelSettings: { modelRoles: roles, ...(defaultThinkingLevel !== undefined ? { defaultThinkingLevel } : {}) } } };
|
|
473
512
|
};
|
|
474
513
|
const handle = async (command: Frame): Promise<unknown> => {
|
|
514
|
+
if (command.type === "stage_reply_voice" || command.type === "clear_reply_voice") {
|
|
515
|
+
exact();
|
|
516
|
+
if (!replyVoice || typeof command.token !== "string" || !command.token)
|
|
517
|
+
throw new Error("Native reply voice control is unavailable");
|
|
518
|
+
if (command.type === "stage_reply_voice") return { staged: replyVoice.stage(command) };
|
|
519
|
+
replyVoice.clear(command.token);
|
|
520
|
+
return {};
|
|
521
|
+
}
|
|
475
522
|
if (command.type === "get_head_rotation") {
|
|
476
523
|
const state = rotationState();
|
|
477
524
|
if (!state) return null;
|
|
@@ -515,6 +562,7 @@ export default function hostExtension(pi: ExtensionAPI): void {
|
|
|
515
562
|
}
|
|
516
563
|
if (command.type === "interrupt_maintenance") {
|
|
517
564
|
const { session } = exact();
|
|
565
|
+
replyVoice?.clear();
|
|
518
566
|
const restored = command.restoreQueue === true ? session.clearQueue({ forInterrupt: true }) : undefined;
|
|
519
567
|
// abort() raises its barrier and withdraws marked internal context before
|
|
520
568
|
// its first await. Do not await its compaction cleanup until the owner has
|
|
@@ -567,12 +615,70 @@ export default function hostExtension(pi: ExtensionAPI): void {
|
|
|
567
615
|
// Only an owner that implements the cursor command can advertise it to peers.
|
|
568
616
|
return { ...ownerIdentity(ownership.identity), loadedSuperkitPath, prReviewPolicy, settingsScope: "session", modelSettings: snapshot(),
|
|
569
617
|
journalCursorControlVersion: 1,
|
|
618
|
+
...(replyVoice?.available() ? { replyVoiceControlVersion: 2 } : {}),
|
|
570
619
|
hasOwnedRunningWork: ownership.unknown ? undefined : ownership.busy, mutationHeld, observationHeld,
|
|
571
620
|
admitted: ownership.identity.session.hasAdmittedSubmission,
|
|
572
621
|
postPromptWork: ownership.identity.session.hasPostPromptWork,
|
|
573
622
|
...(typeof ownership.identity.session.configuredThinkingLevel === "function"
|
|
574
623
|
? { configuredThinkingLevel: ownership.identity.session.configuredThinkingLevel() ?? null } : {}) };
|
|
575
624
|
}
|
|
625
|
+
if (command.type === "set_lane_model") {
|
|
626
|
+
if (reviewCwd || process.env.OMP_SUPERAGENT_ROLE !== "lane")
|
|
627
|
+
throw new Error("An ordinary managed lane Host is required");
|
|
628
|
+
if (!localIdle()) throw new Error("session_busy");
|
|
629
|
+
const ownership = await owned(true);
|
|
630
|
+
const { session, ref, id, file } = ownership.identity;
|
|
631
|
+
if (ownership.unknown || ownership.busy) throw new Error("session_busy");
|
|
632
|
+
// Use the current native catalogue and configured credential source,
|
|
633
|
+
// without resolving a key, refreshing discovery, or probing inference.
|
|
634
|
+
const candidates = session.getAvailableModels().filter(model =>
|
|
635
|
+
model.provider === command.provider && model.id === command.modelId);
|
|
636
|
+
const [model] = candidates;
|
|
637
|
+
if (candidates.length !== 1 || !model || (model.kind !== undefined && model.kind !== "chat")
|
|
638
|
+
|| !session.modelRegistry.hasConfiguredAuth(model))
|
|
639
|
+
throw new Error("An available exact chat model with configured auth is required");
|
|
640
|
+
const previousLeaf = session.sessionManager.getLeafId();
|
|
641
|
+
const before = exact();
|
|
642
|
+
// No await after the final native guard until the stock setter starts.
|
|
643
|
+
if (!file || before.ref !== ref || before.session !== session || before.id !== id || before.file !== file
|
|
644
|
+
|| !localIdle()) throw new Error("session_busy");
|
|
645
|
+
const prior = session.model;
|
|
646
|
+
const promoting = prior?.provider === model.provider && prior.id === model.id;
|
|
647
|
+
mutationHeld = true;
|
|
648
|
+
await session.setModel(model);
|
|
649
|
+
const after = exact();
|
|
650
|
+
const actual = session.model;
|
|
651
|
+
if (after.ref !== ref || after.session !== session || after.id !== id || after.file !== file
|
|
652
|
+
|| actual?.provider !== model.provider || actual.id !== model.id)
|
|
653
|
+
throw new Error("Lane model selection could not be confirmed");
|
|
654
|
+
flushLaneModel(session, previousLeaf, promoting);
|
|
655
|
+
mutationHeld = false;
|
|
656
|
+
return { provider: actual.provider, id: actual.id };
|
|
657
|
+
}
|
|
658
|
+
if (command.type === "set_pr_review_model") {
|
|
659
|
+
if (!reviewCwd || !localIdle()) throw new ReviewIsolationError("Static PR review model selection requires an idle owned review session");
|
|
660
|
+
const ownership = await owned(true);
|
|
661
|
+
const { session, ref } = ownership.identity;
|
|
662
|
+
const previous = session.model;
|
|
663
|
+
if (ownership.unknown || ownership.busy || !localIdle() || exact().ref !== ref
|
|
664
|
+
|| !previous || previous.provider !== command.previousProvider || previous.id !== command.previousModelId) {
|
|
665
|
+
throw new ReviewIsolationError("The previous static PR review model or ownership no longer matches");
|
|
666
|
+
}
|
|
667
|
+
reviewPolicy(session, reviewCwd);
|
|
668
|
+
const model = prReviewModelChoices(session.getAvailableModels()).find(model =>
|
|
669
|
+
model.provider === command.provider && model.id === command.modelId);
|
|
670
|
+
if (!model)
|
|
671
|
+
throw new ReviewIsolationError("Static PR review requires an available exact tool-less inference model");
|
|
672
|
+
const previousLeaf = session.sessionManager.getLeafId();
|
|
673
|
+
mutationHeld = true;
|
|
674
|
+
await session.setModel(model);
|
|
675
|
+
reviewPolicy(session, reviewCwd);
|
|
676
|
+
if (exact().ref !== ref || session.model?.provider !== model.provider || session.model?.id !== model.id)
|
|
677
|
+
throw new ReviewIsolationError("The static PR review model selection could not be confirmed");
|
|
678
|
+
flushLaneModel(session, previousLeaf, previous.provider === model.provider && previous.id === model.id);
|
|
679
|
+
mutationHeld = false;
|
|
680
|
+
return { provider: model.provider, id: model.id };
|
|
681
|
+
}
|
|
576
682
|
if (command.type === "set_model_preset") {
|
|
577
683
|
if (!localIdle()) throw new Error("Native session is busy or has an unresolved mutation");
|
|
578
684
|
const ownership = await owned(true);
|
|
@@ -743,7 +849,12 @@ export default function hostExtension(pi: ExtensionAPI): void {
|
|
|
743
849
|
process.stderr.write(`${error instanceof ReviewIsolationError ? error.message : "Static PR review native guard setup failed"}\n`);
|
|
744
850
|
throw error;
|
|
745
851
|
}
|
|
746
|
-
}
|
|
852
|
+
} else replyVoice = installReplyVoice(pi, identity.session, async token => {
|
|
853
|
+
const response = await ownerChannel?.request({ type: "claim_reply_voice", token });
|
|
854
|
+
return response?.success === true && isDeepStrictEqual(response.data, { claimed: true });
|
|
855
|
+
}, token => {
|
|
856
|
+
ownerChannel?.send({ type: "retire_reply_voice", token });
|
|
857
|
+
});
|
|
747
858
|
await ctx.sessionManager.ensureOnDisk();
|
|
748
859
|
if (exact().ref !== identity.ref) throw new Error("Native session changed during materialization");
|
|
749
860
|
identity.session.sessionManager.flushSync();
|
|
@@ -762,7 +873,11 @@ export default function hostExtension(pi: ExtensionAPI): void {
|
|
|
762
873
|
if (ownerChannel) { socket.destroy(); return; }
|
|
763
874
|
const channel = new HostChannel(socket, socket, true);
|
|
764
875
|
ownerChannel = channel;
|
|
765
|
-
void channel.exited.then(() => {
|
|
876
|
+
void channel.exited.then(() => {
|
|
877
|
+
if (ownerChannel !== channel) return;
|
|
878
|
+
ownerChannel = undefined;
|
|
879
|
+
replyVoice?.clear();
|
|
880
|
+
});
|
|
766
881
|
channel.encoder.setProtocolVersion(2);
|
|
767
882
|
channel.on("frame", (command: Frame) => {
|
|
768
883
|
if (command.type === "response" || typeof command.id !== "string") return;
|
package/src/host-protocol.ts
CHANGED
|
@@ -15,6 +15,7 @@ export const PR_REVIEW_SYSTEM_PROMPT = [
|
|
|
15
15
|
'Otherwise use {"verdict":"blocked","summary":"findings or missing evidence"}.',
|
|
16
16
|
].join("\n");
|
|
17
17
|
export const PR_REVIEW_GITHUB_ENV = ["GH_TOKEN", "GITHUB_TOKEN", "GH_ENTERPRISE_TOKEN", "GITHUB_ENTERPRISE_TOKEN"] as const;
|
|
18
|
+
export const LANE_MODEL_PROMOTION_RECEIPT = "superagent_lane_model_promotion";
|
|
18
19
|
|
|
19
20
|
/** Private adapter observations, not additions to the stock RPC protocol. */
|
|
20
21
|
export type HostState = RpcSessionState & {
|
|
@@ -24,6 +25,7 @@ export type HostState = RpcSessionState & {
|
|
|
24
25
|
readonly loadedSuperkitPath?: string;
|
|
25
26
|
readonly prReviewPolicy?: { readonly version: 1; readonly cwd: string; readonly modelApi: string };
|
|
26
27
|
readonly journalCursorVersion?: 1;
|
|
28
|
+
readonly replyVoiceVersion?: 1 | 2;
|
|
27
29
|
settingsScope: "session";
|
|
28
30
|
modelSettings: LanePresetSnapshot;
|
|
29
31
|
hasOwnedRunningWork: boolean;
|
|
@@ -37,7 +39,10 @@ export type ServiceUnit = Pick<UnitSnapshot, "id" | "key" | "owner" |
|
|
|
37
39
|
};
|
|
38
40
|
export type Response = Frame & { success: boolean; data?: unknown; error?: string };
|
|
39
41
|
export type HostResponse = RpcResponse | {
|
|
40
|
-
type: "response"; id?: string; command: "shutdown_host" | "set_model_preset" | "get_host_admission"; success: true; data: Frame;
|
|
42
|
+
type: "response"; id?: string; command: "shutdown_host" | "set_model_preset" | "set_pr_review_model" | "get_host_admission"; success: true; data: Frame;
|
|
43
|
+
} | {
|
|
44
|
+
type: "response"; id?: string; command: "set_lane_model"; success: true;
|
|
45
|
+
data: { readonly provider: string; readonly id: string };
|
|
41
46
|
} | {
|
|
42
47
|
type: "response"; id?: string; command: "set_host_message_updates"; success: true;
|
|
43
48
|
data: { readonly messageUpdates: "full" | "activity-v1" };
|
|
@@ -74,14 +79,6 @@ function serviceExitKey({ owner, id, generation, startedAt, restartCount, exited
|
|
|
74
79
|
return JSON.stringify([owner, id, generation, String(startedAt), String(restartCount), String(exitedAt)]);
|
|
75
80
|
}
|
|
76
81
|
|
|
77
|
-
/** Positive native journal evidence for this exact terminal service generation. */
|
|
78
|
-
export function serviceCompletionRecorded(daemon: Frame, entries: readonly unknown[]): boolean {
|
|
79
|
-
const key = serviceExitKey(daemon);
|
|
80
|
-
if (key === undefined || !hasValidGeneration(daemon) || !isTerminal(String(daemon.state))) return false;
|
|
81
|
-
return entries.some(entry => launchCompletions(entry)?.some(observed => isFrame(observed)
|
|
82
|
-
&& observed.state === daemon.state && serviceExitKey(observed) === key));
|
|
83
|
-
}
|
|
84
|
-
|
|
85
82
|
/** Builds proof for the current observation only, from one native transcript. */
|
|
86
83
|
export function indexServiceCompletions(entries: readonly unknown[]) {
|
|
87
84
|
const byGeneration = new Set<string>();
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import type { AgentSession, ExtensionAPI } from "@oh-my-pi/pi-coding-agent";
|
|
4
|
+
import { isUserAuthoredMessage } from "@oh-my-pi/pi-coding-agent/session/messages";
|
|
5
|
+
import type { Frame } from "./host-protocol";
|
|
6
|
+
import { renderReplyVoice } from "./soul";
|
|
7
|
+
|
|
8
|
+
type Message = AgentSession["messages"][number];
|
|
9
|
+
type StagedVoice = { readonly token: string; readonly digest: string; readonly voice: string };
|
|
10
|
+
type Binding = StagedVoice & { readonly phase: "staged" | "input" | "submitted" };
|
|
11
|
+
type Submission = {
|
|
12
|
+
readonly token: string;
|
|
13
|
+
kind: "prompt" | "local-command" | "command-prompt";
|
|
14
|
+
admitted: boolean; prepared?: string;
|
|
15
|
+
};
|
|
16
|
+
const wirePrefix = "\0omp-superagent-reply-voice:";
|
|
17
|
+
|
|
18
|
+
const digest = (text: string) => createHash("sha256").update(text).digest("hex");
|
|
19
|
+
const messageText = (message: Extract<Message, { role: "user" }>) =>
|
|
20
|
+
typeof message.content === "string" ? message.content
|
|
21
|
+
: message.content.flatMap(part => part.type === "text" ? [part.text] : []).join("");
|
|
22
|
+
|
|
23
|
+
/** Project into the root's provider call, not its stored or effective session prompt. */
|
|
24
|
+
export function installReplyVoice(pi: ExtensionAPI, session: AgentSession, claim: (token: string) => Promise<boolean>,
|
|
25
|
+
retire: (token: string) => void) {
|
|
26
|
+
const { agent, sessionId, sessionFile, extensionRunner: runner } = session;
|
|
27
|
+
if (typeof agent.addBeforeModelCallHook !== "function" || typeof agent.streamFn !== "function"
|
|
28
|
+
|| typeof session.prompt !== "function" || typeof session.addDisposer !== "function"
|
|
29
|
+
|| typeof session.subscribeRunState !== "function" || !runner || typeof runner.emitInput !== "function") return;
|
|
30
|
+
const sameSession = () => session.sessionId === sessionId && session.sessionFile === sessionFile && !session.isDisposed;
|
|
31
|
+
const idle = () => sameSession() && !session.isRunActive && !session.isBusyForSnapshot
|
|
32
|
+
&& !session.hasAdmittedSubmission && !session.hasPostPromptWork && session.queuedMessageCount === 0;
|
|
33
|
+
const scope = new AsyncLocalStorage<Submission>();
|
|
34
|
+
let binding: Binding | undefined;
|
|
35
|
+
let runVoice: StagedVoice | undefined;
|
|
36
|
+
let approvedSignal: AbortSignal | undefined;
|
|
37
|
+
const clear = (token?: string) => {
|
|
38
|
+
if (token !== undefined && token !== binding?.token) return;
|
|
39
|
+
binding = undefined;
|
|
40
|
+
runVoice = undefined;
|
|
41
|
+
approvedSignal = undefined;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// Keep stock RPC's input path active even when no other extension handles it.
|
|
45
|
+
pi.on("input", () => {});
|
|
46
|
+
const emitInput = runner.emitInput;
|
|
47
|
+
const receive: typeof emitInput = async (text, images, source) => {
|
|
48
|
+
if (source !== "rpc" || !text.startsWith(wirePrefix)) return emitInput.call(runner, text, images, source);
|
|
49
|
+
const separator = text.indexOf("\n", wirePrefix.length);
|
|
50
|
+
if (separator === -1) throw new Error("Invalid owned reply voice input");
|
|
51
|
+
const original = text.slice(separator + 1);
|
|
52
|
+
const candidate = binding;
|
|
53
|
+
if (candidate?.phase !== "staged" || candidate.token !== text.slice(wirePrefix.length, separator)
|
|
54
|
+
|| digest(original) !== candidate.digest) throw new Error("Owned reply voice input did not match its staging");
|
|
55
|
+
// Strip the stock-only marker before other extensions see input; only a
|
|
56
|
+
// pass-through from the complete input hook may bind the RPC prompt.
|
|
57
|
+
const result = await emitInput.call(runner, original, images, source);
|
|
58
|
+
if (binding === candidate && !result.handled && (result.text ?? original) === original && idle()) {
|
|
59
|
+
const claimed = await claim(candidate.token).catch((error: unknown) => {
|
|
60
|
+
if (error instanceof Error) return false;
|
|
61
|
+
throw error;
|
|
62
|
+
});
|
|
63
|
+
if (binding === candidate) {
|
|
64
|
+
if (claimed) binding = { ...candidate, phase: "input" };
|
|
65
|
+
else clear();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return { ...result, text: result.text ?? original };
|
|
69
|
+
};
|
|
70
|
+
pi.on("before_agent_start", (event, ctx) => {
|
|
71
|
+
const submission = scope.getStore();
|
|
72
|
+
if (ctx.agent.kind === "main" && ctx.sessionManager === session.sessionManager && event.reason === "prompt"
|
|
73
|
+
&& submission?.admitted && submission.token === binding?.token && !runVoice) {
|
|
74
|
+
submission.prepared ??= digest(event.prompt);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const prompt = session.prompt;
|
|
79
|
+
// The private marker was consumed by the stock input carrier, not shown
|
|
80
|
+
// to a model. Observe its matching admission and actual new root input.
|
|
81
|
+
const boundPrompt: typeof prompt = (text, options) => {
|
|
82
|
+
const inherited = scope.getStore();
|
|
83
|
+
if (inherited?.kind === "local-command" && inherited.token === binding?.token && sameSession()
|
|
84
|
+
&& !session.isStreaming && !session.isRunActive
|
|
85
|
+
&& options?.expandPromptTemplates === false && options.throwOnDrop === true && options.streamingBehavior === "steer"
|
|
86
|
+
&& (options.attribution === undefined || options.attribution === "user")) {
|
|
87
|
+
// An extension command (such as a workflow alias) can handle the slash
|
|
88
|
+
// locally and submit its real user turn through pi.sendUserMessage.
|
|
89
|
+
// Use that SDK call's scoped admission, not the slash or rewritten text.
|
|
90
|
+
inherited.kind = "command-prompt";
|
|
91
|
+
return prompt.call(session, text, {
|
|
92
|
+
...options,
|
|
93
|
+
onPromptAdmitted: () => { inherited.admitted = session.isStreaming && !agent.state.isStreaming; },
|
|
94
|
+
}).finally(() => { if (runVoice?.token !== inherited.token) clear(inherited.token); });
|
|
95
|
+
}
|
|
96
|
+
const notify = options?.onPromptAdmitted;
|
|
97
|
+
if (binding?.phase !== "input" || !idle() || !options || typeof notify !== "function"
|
|
98
|
+
|| options.streamingBehavior !== undefined
|
|
99
|
+
|| !Object.hasOwn(options, "images") || !Object.hasOwn(options, "streamingBehavior") || Object.keys(options).length !== 3
|
|
100
|
+
|| digest(text) !== binding.digest) {
|
|
101
|
+
return scope.exit(() => prompt.call(session, text, options));
|
|
102
|
+
}
|
|
103
|
+
const { token } = binding;
|
|
104
|
+
binding = { ...binding, phase: "submitted" };
|
|
105
|
+
const submission: Submission = { token, kind: "prompt", admitted: false };
|
|
106
|
+
return scope.run(submission, () => prompt.call(session, text, {
|
|
107
|
+
...options,
|
|
108
|
+
onPromptAdmitted: () => {
|
|
109
|
+
// An idle SDK prompt routed to a local command fires the same
|
|
110
|
+
// callback before its handler, but has not claimed prompt setup.
|
|
111
|
+
submission.admitted = session.isStreaming && !agent.state.isStreaming;
|
|
112
|
+
if (!submission.admitted && !session.isStreaming) submission.kind = "local-command";
|
|
113
|
+
notify();
|
|
114
|
+
},
|
|
115
|
+
})).finally(() => {
|
|
116
|
+
if (submission.kind !== "command-prompt" && runVoice?.token !== token) clear(token);
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const dispatch = agent.streamFn;
|
|
121
|
+
const project: typeof dispatch = (model, input, options) => {
|
|
122
|
+
const voice = approvedSignal && !approvedSignal.aborted && session.isRunActive && sameSession()
|
|
123
|
+
&& !options?.signal?.aborted ? runVoice?.voice : undefined;
|
|
124
|
+
return dispatch(model, voice ? { ...input, systemPrompt: [...(input.systemPrompt ?? []), voice] } : input, options);
|
|
125
|
+
};
|
|
126
|
+
const unhook = agent.addBeforeModelCallHook((signal, context) => {
|
|
127
|
+
approvedSignal = undefined;
|
|
128
|
+
if (!sameSession() || !session.isRunActive || !signal || signal.aborted) return;
|
|
129
|
+
// A paused root run may resume in a fresh loop (and signal) to consume
|
|
130
|
+
// background work. The public run boundary, not the loop, owns the voice.
|
|
131
|
+
if (runVoice) { approvedSignal = signal; return; }
|
|
132
|
+
const submission = scope.getStore();
|
|
133
|
+
if (!submission?.admitted || !binding || submission.token !== binding.token) return;
|
|
134
|
+
// The first call's new input is in the loop context but has not yet
|
|
135
|
+
// emitted message_end. Use the current history after any pre-send rewrite.
|
|
136
|
+
const previousUser = agent.state.messages.findLast(isUserAuthoredMessage);
|
|
137
|
+
const previousIndex = previousUser ? context.messages.lastIndexOf(previousUser) : -1;
|
|
138
|
+
const firstUser = context.messages.find((message, index) => index > previousIndex && isUserAuthoredMessage(message));
|
|
139
|
+
if (firstUser?.role !== "user" || digest(messageText(firstUser)) !== submission.prepared) {
|
|
140
|
+
clear(submission.token);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
submission.prepared = undefined;
|
|
144
|
+
runVoice = binding;
|
|
145
|
+
approvedSignal = signal;
|
|
146
|
+
});
|
|
147
|
+
const unwatch = session.subscribeRunState(state => {
|
|
148
|
+
if (state === "idle" && runVoice) {
|
|
149
|
+
const { token } = runVoice;
|
|
150
|
+
clear(token);
|
|
151
|
+
retire(token);
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
runner.emitInput = receive;
|
|
155
|
+
session.prompt = boundPrompt;
|
|
156
|
+
agent.streamFn = project;
|
|
157
|
+
session.addDisposer(() => {
|
|
158
|
+
clear();
|
|
159
|
+
unwatch();
|
|
160
|
+
unhook();
|
|
161
|
+
if (runner.emitInput === receive) runner.emitInput = emitInput;
|
|
162
|
+
if (session.prompt === boundPrompt) session.prompt = prompt;
|
|
163
|
+
if (agent.streamFn === project) agent.streamFn = dispatch;
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
const available = () => sameSession() && session.extensionRunner === runner && runner.emitInput === receive
|
|
167
|
+
&& session.prompt === boundPrompt && agent.streamFn === project;
|
|
168
|
+
return {
|
|
169
|
+
available, clear,
|
|
170
|
+
stage(command: Frame): boolean {
|
|
171
|
+
const { token, message } = command;
|
|
172
|
+
if (!available() || binding || typeof token !== "string" || !token || typeof message !== "string") {
|
|
173
|
+
throw new Error("Native reply voice cannot be staged");
|
|
174
|
+
}
|
|
175
|
+
const voice = renderReplyVoice(command.voice);
|
|
176
|
+
if (!idle()) return false;
|
|
177
|
+
binding = { token, digest: digest(message), voice, phase: "staged" };
|
|
178
|
+
return true;
|
|
179
|
+
},
|
|
180
|
+
};
|
|
181
|
+
}
|
package/src/lane-extension.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { resolve } from "node:path";
|
|
|
4
4
|
import type { ToolCall, ToolResultMessage } from "@oh-my-pi/pi-ai";
|
|
5
5
|
import type { ExtensionAPI, ExtensionContext } from "@oh-my-pi/pi-coding-agent";
|
|
6
6
|
import { type Static, Type } from "@sinclair/typebox";
|
|
7
|
-
import { type LaneEvidence, type LaneReportEvent, parseLaneReportResult } from "./lane-report";
|
|
7
|
+
import { type LaneEvidence, type LaneReportEvent, type ScopeReviewReceipt, parseLaneReportResult } from "./lane-report";
|
|
8
8
|
import { registerResultAttach, RESULT_ATTACH_TOOL } from "./result-attachment";
|
|
9
9
|
import { registerDecisionAsk } from "./decision-tool";
|
|
10
10
|
|
|
@@ -29,6 +29,7 @@ const parameters = Type.Union([
|
|
|
29
29
|
{ additionalProperties: false }),
|
|
30
30
|
Type.Object({ status: Type.Literal("resolved"), summary, waiting, evidence: requiredEvidence },
|
|
31
31
|
{ additionalProperties: false }),
|
|
32
|
+
Type.Object({ status: Type.Literal("scope_review"), sourceId: nonempty }, { additionalProperties: false }),
|
|
32
33
|
]);
|
|
33
34
|
const coordinationTool = (name: string) => name === "lane_report" || name === RESULT_ATTACH_TOOL || name.startsWith("board_");
|
|
34
35
|
const record = (value: unknown): value is Record<string, unknown> =>
|
|
@@ -39,7 +40,12 @@ const keys = (value: Record<string, unknown>, names: string[]) =>
|
|
|
39
40
|
|
|
40
41
|
// Direct native/custom-tool dispatch can bypass model argument validation.
|
|
41
42
|
function validInput(input: unknown): input is Static<typeof parameters> {
|
|
42
|
-
if (!record(input)
|
|
43
|
+
if (!record(input)) return false;
|
|
44
|
+
if (input.status === "scope_review") {
|
|
45
|
+
return Object.hasOwn(input, "status") && Object.hasOwn(input, "sourceId") &&
|
|
46
|
+
keys(input, ["status", "sourceId"]) && text(input.sourceId);
|
|
47
|
+
}
|
|
48
|
+
if (!keys(input, ["status", "summary", "waiting", "evidence"]) ||
|
|
43
49
|
!text(input.summary) || input.summary.length > 4000 ||
|
|
44
50
|
!["progress", "waiting", "resolved"].includes(input.status as string)) return false;
|
|
45
51
|
if (input.evidence !== undefined && (!Array.isArray(input.evidence) || input.evidence.length > 32 ||
|
|
@@ -111,12 +117,12 @@ function toolEvidence(id: string, records: ReturnType<typeof toolRecords>): Lane
|
|
|
111
117
|
if (!call || !result || result.toolName !== call.name || result.isError !== false ||
|
|
112
118
|
coordinationTool(call.name) || (typeof call.arguments.path === "string" &&
|
|
113
119
|
/^xd:\/\/(?:lane_report|board_[a-z_]+)(?:[/?#]|$)/.test(call.arguments.path)) ||
|
|
114
|
-
parseLaneReportResult(result)) {
|
|
120
|
+
parseLaneReportResult(result) || (record(result.details) && result.details.type === "superagent-scope-review")) {
|
|
115
121
|
throw new Error("Lane tool evidence requires a completed successful native tool call, not report/board chatter");
|
|
116
122
|
}
|
|
117
123
|
// Native identity/time envelopes are not evidence of changed work.
|
|
118
|
-
const
|
|
119
|
-
return { kind: "tool", ref: id, fingerprint: createHash("sha256").update(JSON.stringify(
|
|
124
|
+
const resultRecord = { toolName: result.toolName, content: result.content, details: result.details, isError: result.isError };
|
|
125
|
+
return { kind: "tool", ref: id, fingerprint: createHash("sha256").update(JSON.stringify(resultRecord)).digest("hex") };
|
|
120
126
|
}
|
|
121
127
|
|
|
122
128
|
/** A worker role entrypoint, never the head's manager or messenger client. */
|
|
@@ -126,10 +132,12 @@ export default function laneExtension(pi: ExtensionAPI): void {
|
|
|
126
132
|
registerResultAttach(pi);
|
|
127
133
|
let approvalSessionId: string | undefined;
|
|
128
134
|
const pendingApprovals = new Set<string>();
|
|
135
|
+
const scopeApprovals = new Map<string, "requested" | "approved" | "unverified">();
|
|
129
136
|
const approvals = (ctx: ExtensionContext) => {
|
|
130
137
|
const sessionId = ctx.sessionManager.getSessionId();
|
|
131
138
|
if (approvalSessionId !== sessionId) {
|
|
132
139
|
pendingApprovals.clear();
|
|
140
|
+
scopeApprovals.clear();
|
|
133
141
|
approvalSessionId = sessionId;
|
|
134
142
|
}
|
|
135
143
|
return pendingApprovals;
|
|
@@ -154,12 +162,22 @@ export default function laneExtension(pi: ExtensionAPI): void {
|
|
|
154
162
|
pi.on("tool_approval_requested", (event, ctx) => {
|
|
155
163
|
if (ctx.agent.kind === "main" && event.sessionId === ctx.sessionManager.getSessionId()) {
|
|
156
164
|
approvals(ctx).add(event.toolCallId);
|
|
165
|
+
if (event.toolName === "lane_report")
|
|
166
|
+
scopeApprovals.set(event.toolCallId, scopeApprovals.has(event.toolCallId) ? "unverified" : "requested");
|
|
157
167
|
}
|
|
158
168
|
});
|
|
159
169
|
pi.on("tool_approval_resolved", (event, ctx) => {
|
|
160
|
-
if (event.sessionId
|
|
170
|
+
if (event.sessionId !== ctx.sessionManager.getSessionId()) return;
|
|
171
|
+
approvals(ctx).delete(event.toolCallId);
|
|
172
|
+
if (ctx.agent.kind === "main" && event.toolName === "lane_report")
|
|
173
|
+
scopeApprovals.set(event.toolCallId,
|
|
174
|
+
event.approved && scopeApprovals.get(event.toolCallId) === "requested" ? "approved" : "unverified");
|
|
175
|
+
});
|
|
176
|
+
pi.on("agent_end", (_event, ctx) => { if (ctx.agent.kind === "main") scopeApprovals.clear(); });
|
|
177
|
+
pi.on("session_shutdown", () => {
|
|
178
|
+
pendingApprovals.clear();
|
|
179
|
+
scopeApprovals.clear();
|
|
161
180
|
});
|
|
162
|
-
pi.on("session_shutdown", () => { pendingApprovals.clear(); });
|
|
163
181
|
pi.on("before_agent_start", async (event, ctx) => {
|
|
164
182
|
if (ctx.agent.kind !== "main") return;
|
|
165
183
|
return { systemPrompt: [
|
|
@@ -173,11 +191,31 @@ export default function laneExtension(pi: ExtensionAPI): void {
|
|
|
173
191
|
description: "Record an evidence-backed progress, waiting, or resolved observation in this lane's native tool journal. " +
|
|
174
192
|
"Progress/resolved require selected real file paths or completed successful native toolCallIds; hashes are computed here. " +
|
|
175
193
|
"Waiting/resolved name the exact tool/approval/job ID or a dependency label. Native tool/approval/job waiting IDs must be observable now. " +
|
|
194
|
+
"For a standalone original owner message in the active bound topic that appears to supersede the existing assignment, " +
|
|
195
|
+
"call lane_report directly with status scope_review and its Original source ID, never via eval, bash, or write. " +
|
|
196
|
+
"This only requests HEAD review; it does not grant permission. " +
|
|
176
197
|
"Reports do not send messages, prove acceptance, dispatch, resume, or change execution authority. Board/report chatter is not evidence.",
|
|
177
198
|
parameters,
|
|
178
|
-
async execute(id, params,
|
|
199
|
+
async execute(id, params, signal, _onUpdate, ctx) {
|
|
179
200
|
if (ctx.agent.kind !== "main") throw new Error("Lane reporting is restricted to the root lane session");
|
|
180
201
|
if (!validInput(params)) throw new Error("Invalid lane report parameters");
|
|
202
|
+
approvals(ctx);
|
|
203
|
+
const nativeApproval = scopeApprovals.get(id);
|
|
204
|
+
scopeApprovals.delete(id);
|
|
205
|
+
if (params.status === "scope_review") {
|
|
206
|
+
signal?.throwIfAborted();
|
|
207
|
+
const sessionFile = ctx.sessionManager.getSessionFile();
|
|
208
|
+
if (!sessionFile) throw new Error("Lane scope review requires a native session file");
|
|
209
|
+
const receipt: ScopeReviewReceipt = {
|
|
210
|
+
type: "superagent-scope-review", sourceId: params.sourceId,
|
|
211
|
+
sessionId: ctx.sessionManager.getSessionId(), sessionFile, toolCallId: id,
|
|
212
|
+
};
|
|
213
|
+
// Only a matched direct native start/end can request review. Do not append a custom entry.
|
|
214
|
+
return {
|
|
215
|
+
content: [{ type: "text", text: "Emitted a scope-review signal. HEAD admission depends on controller verification and successful settlement; the assignment has not changed." }],
|
|
216
|
+
details: nativeApproval === undefined ? receipt : { ...receipt, nativeApproval },
|
|
217
|
+
};
|
|
218
|
+
}
|
|
181
219
|
const target = params.status === "waiting" ? params.waiting : undefined;
|
|
182
220
|
if (target?.kind === "approval" && !approvals(ctx).has(target.id)) {
|
|
183
221
|
throw new Error("Lane approval wait requires an observed pending native tool approval");
|
package/src/lane-models.ts
CHANGED
|
@@ -21,6 +21,14 @@ export function isLaneModel(value: unknown): value is LaneModel {
|
|
|
21
21
|
typeof model.id === "string" && !!model.id.trim() && !model.id.includes("\0");
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
// Match worker_rpc::model_id: Rust char::is_whitespace / char::is_control.
|
|
25
|
+
const invalidRestrictedSelector = /[\p{White_Space}\p{Cc}]/u;
|
|
26
|
+
|
|
27
|
+
/** The narrow exact-selector wire used by remote workers and static PR Hosts. */
|
|
28
|
+
export function acceptsRestrictedModelSelector(model: LaneModel): boolean {
|
|
29
|
+
return !!model.provider && !!model.id && !invalidRestrictedSelector.test(model.provider) && !invalidRestrictedSelector.test(model.id);
|
|
30
|
+
}
|
|
31
|
+
|
|
24
32
|
/** Project native catalog facts only: endpoints, headers, credentials and opaque internals never leave here. */
|
|
25
33
|
export function codingModels(value: unknown): LaneModelCandidate[] {
|
|
26
34
|
if (!Array.isArray(value)) throw new Error("Native available-model response is missing its model list");
|