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/lane-report.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isAbsolute, normalize } from "node:path";
|
|
2
|
+
import { isDeepStrictEqual } from "node:util";
|
|
2
3
|
|
|
3
4
|
export type LaneWaitTarget =
|
|
4
5
|
| { kind: "tool" | "approval" | "job"; id: string; target: string }
|
|
@@ -24,6 +25,27 @@ export interface LaneReportEvent {
|
|
|
24
25
|
report: LaneReport;
|
|
25
26
|
}
|
|
26
27
|
|
|
28
|
+
/** Evidence of a tool execution only; it does not authorize a scope change. */
|
|
29
|
+
export type ScopeReviewReceipt = {
|
|
30
|
+
readonly type: "superagent-scope-review";
|
|
31
|
+
readonly sourceId: string;
|
|
32
|
+
readonly sessionId: string;
|
|
33
|
+
readonly sessionFile: string;
|
|
34
|
+
readonly toolCallId: string;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/** Stock OMP select wire for this tool. A positive answer describes this call
|
|
38
|
+
* only; the native Host, not the controller, handles any session-wide choice. */
|
|
39
|
+
export function scopeReviewApproval(request: Record<string, unknown>, response?: { value?: string }): boolean {
|
|
40
|
+
if (request.method !== "select" || request.secret === true) return false;
|
|
41
|
+
const options = request.options;
|
|
42
|
+
const session = "Approve lane_report for this session";
|
|
43
|
+
if (!isDeepStrictEqual(options, ["Approve", "Deny"]) && !isDeepStrictEqual(options, ["Approve", session, "Deny"])) return false;
|
|
44
|
+
if (!response) return true;
|
|
45
|
+
return isDeepStrictEqual(response, { value: "Approve" })
|
|
46
|
+
|| Array.isArray(options) && options.includes(session) && isDeepStrictEqual(response, { value: session });
|
|
47
|
+
}
|
|
48
|
+
|
|
27
49
|
export function laneWaitKey(waiting: LaneWaitTarget): string {
|
|
28
50
|
return JSON.stringify([waiting.kind, waiting.kind === "dependency" ? waiting.target : waiting.id]);
|
|
29
51
|
}
|
package/src/managed-ulw-probe.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Finite native prompt-composition gate, not a model turn or workflow execution.
|
|
2
2
|
import assert from "node:assert/strict";
|
|
3
3
|
import { mkdir, readFile, realpath } from "node:fs/promises";
|
|
4
|
-
import { dirname, join, resolve } from "node:path";
|
|
4
|
+
import { dirname, join, resolve, sep } from "node:path";
|
|
5
5
|
import { getBundledModel, getBundledProviders } from "@oh-my-pi/pi-catalog";
|
|
6
6
|
import { ModelRegistry, Settings, AuthStorage, SessionManager, createAgentSession } from "@oh-my-pi/pi-coding-agent";
|
|
7
7
|
import { ExtensionRunner } from "@oh-my-pi/pi-coding-agent/extensibility/extensions/runner";
|
|
@@ -10,6 +10,7 @@ import { buildAvailableSlashCommands } from "@oh-my-pi/pi-coding-agent/slash-com
|
|
|
10
10
|
import { buildSystemPrompt } from "@oh-my-pi/pi-coding-agent/system-prompt";
|
|
11
11
|
import { WORKFLOW_NAMES } from "./contracts";
|
|
12
12
|
import { readManagedUlwPackage } from "./managed-ulw";
|
|
13
|
+
import { canonicalSuperkitSkills, hasCanonicalSuperkitSkills, legacySuperkitSkills, superkitWorkflows as workflows } from "./superkit-skills";
|
|
13
14
|
import { advertisedWorkflow } from "./workflow";
|
|
14
15
|
|
|
15
16
|
const packageArg = process.argv[2];
|
|
@@ -23,18 +24,13 @@ let networkAttempts = 0;
|
|
|
23
24
|
const refuseNetwork = () => { networkAttempts++; throw new Error("Managed Superkit probe forbids network and provider calls"); };
|
|
24
25
|
globalThis.fetch = Object.assign(async () => refuseNetwork(), { preconnect: refuseNetwork });
|
|
25
26
|
|
|
26
|
-
// Public command names changed; installed skill IDs (also legacy commands,
|
|
27
|
-
// except ultrawork) and the prompt/journal protocol did not.
|
|
28
|
-
const workflows = [
|
|
29
|
-
["super-plan", "ulw-plan"],
|
|
30
|
-
["super-run", "ulw-execute"],
|
|
31
|
-
["super-loop", "ulw-loop"],
|
|
32
|
-
["super-graph", "mass-ulw"],
|
|
33
|
-
["super-research", "ulw-research"],
|
|
34
|
-
] as const;
|
|
35
27
|
const skillPath = (id: string) => join(packagePath, "skills", id, "SKILL.md");
|
|
36
|
-
const
|
|
37
|
-
|
|
28
|
+
const canonicalLayout = hasCanonicalSuperkitSkills(packagePath);
|
|
29
|
+
const directiveId = (canonicalLayout ? canonicalSuperkitSkills : legacySuperkitSkills)[0];
|
|
30
|
+
const directivePath = await realpath(skillPath(directiveId));
|
|
31
|
+
assert(directivePath.startsWith(packagePath + sep), `Managed Superkit skill leaves its package: ${directiveId}`);
|
|
32
|
+
const directive = /<ultrawork-mode>([\s\S]*?)<\/ultrawork-mode>/.exec(await readFile(directivePath, "utf8"))?.[1];
|
|
33
|
+
assert(directive?.trim(), `Managed Superkit must ship a directive in its installed ${directiveId} skill`);
|
|
38
34
|
|
|
39
35
|
const modules = await listPackageExtensionModules([packagePath], process.cwd(), { plugins: false });
|
|
40
36
|
assert.deepEqual(await Promise.all(modules.map(module => realpath(module.path))), extensionFiles,
|
|
@@ -113,7 +109,7 @@ try {
|
|
|
113
109
|
if (workflow) {
|
|
114
110
|
const policy = /<omp-ulw-policy>\s*<ultrawork-mode>([\s\S]*?)<\/ultrawork-mode>\s*<\/omp-ulw-policy>/.exec(text)?.[1];
|
|
115
111
|
assert(policy && policy.trim().length > 200, "Activated SUPER policy must contain the workflow directive");
|
|
116
|
-
assert.equal(policy, directive,
|
|
112
|
+
assert.equal(policy, directive, `Activated SUPER policy must use the installed ${directiveId} directive`);
|
|
117
113
|
assert(!nativeBase.join("\n\n").includes(policy), "Workflow policy must come from the candidate hook");
|
|
118
114
|
}
|
|
119
115
|
assert.deepEqual(errors, [], "Managed Superkit native hooks failed");
|
|
@@ -129,11 +125,15 @@ try {
|
|
|
129
125
|
typeof message === "object" && "customType" in message && message.customType === "omo-ultrawork:directive" ? [message] : []);
|
|
130
126
|
assert.equal(pointers.length, selected ? 1 : 0, "Only an explicitly selected specialized SUPER invocation may add a workflow directive");
|
|
131
127
|
if (selected) {
|
|
132
|
-
const [command,
|
|
128
|
+
const [command, legacyId] = selected;
|
|
129
|
+
const skill = canonicalLayout ? command : legacyId;
|
|
130
|
+
const path = skillPath(skill);
|
|
133
131
|
const content = pointers[0]?.content;
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
132
|
+
// In the canonical layout the path already contains the command name.
|
|
133
|
+
// Check the invocation separately without prescribing pointer formatting.
|
|
134
|
+
assert(typeof content === "string" && content.startsWith(`<omp-${legacyId}-pointer>`) && content.endsWith(`</omp-${legacyId}-pointer>`)
|
|
135
|
+
&& content.includes(path) && content.split(path).some(part => part.includes(command)),
|
|
136
|
+
`SUPER directive must name /${command} and point to its installed ${skill} skill`);
|
|
137
137
|
}
|
|
138
138
|
return blocks;
|
|
139
139
|
};
|
|
@@ -190,18 +190,20 @@ try {
|
|
|
190
190
|
}
|
|
191
191
|
assert(resources.getEnabledToolNames().includes("read"), "Native read must remain available");
|
|
192
192
|
assert(resources.getEnabledToolNames().includes("task"), "Native task must remain available");
|
|
193
|
-
const skills = resources.skills.filter(skill => skill.filePath.startsWith(packagePath +
|
|
194
|
-
for (const id of [
|
|
193
|
+
const skills = resources.skills.filter(skill => skill.filePath.startsWith(packagePath + sep));
|
|
194
|
+
for (const id of canonicalLayout ? [...canonicalSuperkitSkills, ...legacySuperkitSkills] : legacySuperkitSkills) {
|
|
195
195
|
assert.equal(skills.find(skill => skill.name === id)?.filePath, skillPath(id),
|
|
196
196
|
`Native Superkit skill discovery must retain skill://${id} and its installed path`);
|
|
197
197
|
}
|
|
198
198
|
const read = resources.getToolByName("read");
|
|
199
199
|
assert(read, "Native read tool must be resolvable");
|
|
200
200
|
for (const skill of skills) {
|
|
201
|
+
const target = await realpath(skill.filePath);
|
|
202
|
+
assert(target.startsWith(packagePath + sep), `Managed Superkit skill leaves its package: ${skill.name}`);
|
|
201
203
|
const uri = `skill://${skill.name}:raw`;
|
|
202
204
|
const output = await read.execute(`managed-ulw-resource-${resourceReads.length}`, { path: uri });
|
|
203
205
|
const text = output.content.flatMap(block => block.type === "text" ? [block.text] : []).join("\n");
|
|
204
|
-
assert.equal(text, await readFile(
|
|
206
|
+
assert.equal(text, await readFile(target, "utf8"), `Native resource differs from ${skill.filePath}`);
|
|
205
207
|
resourceReads.push(uri);
|
|
206
208
|
}
|
|
207
209
|
assert.equal(resources.isStreaming, false);
|
package/src/message-order.ts
CHANGED
|
@@ -2,7 +2,8 @@ import type { Platform } from "./contracts";
|
|
|
2
2
|
|
|
3
3
|
/** Platform message order only; event/edit IDs and local arrival times are not clocks. */
|
|
4
4
|
export function compareMessageIds(platform: Platform, left: string, right: string): -1 | 0 | 1 | null {
|
|
5
|
-
|
|
5
|
+
// Kakao log IDs are numeric and increase within a chat.
|
|
6
|
+
if (platform === "discord" || platform === "telegram" || platform === "kakao") {
|
|
6
7
|
if (!/^\d+$/.test(left) || !/^\d+$/.test(right)) return null;
|
|
7
8
|
const a = BigInt(left);
|
|
8
9
|
const b = BigInt(right);
|
|
@@ -4,14 +4,17 @@
|
|
|
4
4
|
{ "name": "status", "description": "Inspect Superagent HEAD and this conversation's lane, including while busy." },
|
|
5
5
|
{ "name": "restart", "description": "Interrupt HEAD work and restart Superagent Gateway and HEAD with the same session and memory." },
|
|
6
6
|
{ "name": "context", "description": "Inspect Superagent HEAD context without starting a model turn." },
|
|
7
|
-
{ "name": "usage", "description": "Show Superagent's OMP quotas or open the saved reset picker.", "text": "Omit to view quotas, or enter reset to choose an account and confirm using one saved reset."
|
|
7
|
+
{ "name": "usage", "description": "Show Superagent's OMP quotas or open the saved reset picker.", "text": "Omit to view quotas, or enter reset to choose an account and confirm using one saved reset.",
|
|
8
|
+
"discord": { "description": "Show Superagent's OMP quotas.", "text": false } },
|
|
8
9
|
{ "name": "cron", "description": "Schedule and manage Superagent jobs in this conversation.", "text": "Use help, add, list, show, edit, pause, resume, run or remove." },
|
|
9
10
|
{ "name": "resume", "description": "Resume the Superagent lane bound to this conversation." },
|
|
10
11
|
{ "name": "resolve", "description": "Close an uncertain Superagent HEAD or bound lane input without replay.", "text": "Exact uncertain HEAD input ID, or --lane followed by the bound lane's exact input ID." },
|
|
11
12
|
{ "name": "main", "description": "Select the main Superagent topic in this owner DM." },
|
|
12
|
-
{ "name": "model", "description": "Choose a Superagent HEAD model
|
|
13
|
+
{ "name": "model", "description": "Choose a Superagent HEAD model or preset, or use --lane for the bound lane.", "text": "Omit for the menu, or enter list, provider/model, --lane provider/model, or a preset command.",
|
|
14
|
+
"discord": { "description": "Choose a model for the Superagent HEAD or the current lane.", "text": true } },
|
|
13
15
|
{ "name": "effort", "description": "Choose the Superagent HEAD thinking effort.", "text": "Omit for the menu, or enter an exact advertised effort level." },
|
|
14
16
|
{ "name": "compact", "description": "Compact Superagent HEAD context when idle.", "text": "Optional compaction instructions, including multiple lines." },
|
|
15
17
|
{ "name": "stop", "description": "Stop Superagent work in this conversation, the shared HEAD, or a named lane.", "text": "Omit for this conversation, or specify head or an exact lane ID." },
|
|
16
|
-
{ "name": "new", "description": "Start a Superagent work topic; use a sibling for a new request in an existing thread.", "text": "An optional first request for the new topic." }
|
|
18
|
+
{ "name": "new", "description": "Start a Superagent work topic; use a sibling for a new request in an existing thread.", "text": "An optional first request for the new topic." },
|
|
19
|
+
{ "name": "usage-reset", "description": "Choose an OMP account and review a saved usage reset in Superagent.", "discordOnly": true }
|
|
17
20
|
]
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import catalog from "./messenger-command-catalog.json" with { type: "json" };
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
export const
|
|
3
|
+
/** Owner controls and platform-specific registration metadata shared with the native Gateway. */
|
|
4
|
+
export const MESSENGER_COMMAND_CATALOG: readonly {
|
|
5
5
|
readonly name: string;
|
|
6
6
|
readonly description: string;
|
|
7
7
|
readonly text?: string;
|
|
8
|
+
readonly discordOnly?: boolean;
|
|
9
|
+
readonly discord?: {
|
|
10
|
+
readonly description: string;
|
|
11
|
+
readonly text: boolean;
|
|
12
|
+
};
|
|
8
13
|
}[] = catalog;
|
|
14
|
+
|
|
15
|
+
export const MESSENGER_COMMANDS = MESSENGER_COMMAND_CATALOG.filter(command => !command.discordOnly);
|
package/src/operator.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { addAbortListener } from "node:events";
|
|
2
|
+
import { requireGateway } from "./gateway-native";
|
|
3
|
+
import { readCredentialFile, validateCredential } from "./credentials";
|
|
4
|
+
|
|
5
|
+
type Credentials = { readonly bot: string; readonly manifest?: string };
|
|
6
|
+
export type OperatorRun = <T>(operation: string, request: unknown, credentials: Credentials, signal?: AbortSignal) => Promise<T>;
|
|
7
|
+
|
|
8
|
+
export class OperatorStartError extends Error {
|
|
9
|
+
constructor() { super("Could not start the native operator; no mutation was attempted."); }
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function operatorBotToken(platform: "Discord" | "Telegram", configPath: string, tokenEnv: string): string {
|
|
13
|
+
const explicit = process.env[tokenEnv];
|
|
14
|
+
let stored: string | undefined;
|
|
15
|
+
try {
|
|
16
|
+
// Validate the sibling's ownership even when an explicit environment value wins.
|
|
17
|
+
stored = readCredentialFile(configPath)?.values[tokenEnv];
|
|
18
|
+
if (!explicit && stored) validateCredential(stored);
|
|
19
|
+
} catch { throw new Error(`Cannot safely load the configured ${platform} credential; details suppressed`); }
|
|
20
|
+
if (explicit) {
|
|
21
|
+
try { validateCredential(explicit); }
|
|
22
|
+
catch { throw new Error(`Configured ${platform} credential is invalid; value suppressed`); }
|
|
23
|
+
return explicit;
|
|
24
|
+
}
|
|
25
|
+
if (!stored) throw new Error(`Configured ${platform} credential is missing`);
|
|
26
|
+
return stored;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Run only the selected operation's credentials through the child's private environment. */
|
|
30
|
+
export async function invokeOperator<T>(argv: string[], request: unknown, credentials: Credentials, signal?: AbortSignal): Promise<T> {
|
|
31
|
+
let child: Bun.Subprocess<"pipe", "pipe", "ignore">;
|
|
32
|
+
let frame: string;
|
|
33
|
+
try {
|
|
34
|
+
if (signal?.aborted) throw new OperatorStartError();
|
|
35
|
+
frame = `${JSON.stringify(request)}\n`;
|
|
36
|
+
if (signal?.aborted) throw new OperatorStartError();
|
|
37
|
+
child = Bun.spawn(argv, {
|
|
38
|
+
env: { OMP_SA_OPERATOR_PARENT: String(process.pid), OMP_SA_OPERATOR_BOT: credentials.bot,
|
|
39
|
+
...(credentials.manifest !== undefined && { OMP_SA_OPERATOR_MANIFEST: credentials.manifest }) },
|
|
40
|
+
stdin: "pipe", stdout: "pipe", stderr: "ignore",
|
|
41
|
+
});
|
|
42
|
+
} catch {
|
|
43
|
+
throw new OperatorStartError();
|
|
44
|
+
}
|
|
45
|
+
const uncertain = "No authoritative operator receipt. A requested change may have reached the platform; inspect before retrying.";
|
|
46
|
+
const stop = () => {
|
|
47
|
+
if (child.exitCode === null && child.signalCode === null) child.kill("SIGKILL");
|
|
48
|
+
};
|
|
49
|
+
using abortListener = signal && addAbortListener(signal, stop);
|
|
50
|
+
if (signal?.aborted) stop();
|
|
51
|
+
const send = async () => {
|
|
52
|
+
// Keep the writer open after this frame. EOF is a parent-lifetime fence,
|
|
53
|
+
// including when a supervisor kills only the CLI and no JS handlers run.
|
|
54
|
+
await child.stdin.write(frame);
|
|
55
|
+
await child.stdin.flush();
|
|
56
|
+
};
|
|
57
|
+
try {
|
|
58
|
+
const [code, output] = await Promise.all([child.exited, new Response(child.stdout).text(), send()])
|
|
59
|
+
.catch(() => { throw new Error(uncertain); });
|
|
60
|
+
if (signal?.aborted) throw new Error(uncertain);
|
|
61
|
+
let reply: { ok?: boolean; error?: string; value?: T };
|
|
62
|
+
try { reply = JSON.parse(output); }
|
|
63
|
+
catch { throw new Error(uncertain); }
|
|
64
|
+
if (reply?.ok === false && typeof reply.error === "string") throw new Error(reply.error);
|
|
65
|
+
if (code !== 0 || reply?.ok !== true || reply.value === undefined) throw new Error(uncertain);
|
|
66
|
+
return reply.value;
|
|
67
|
+
} finally {
|
|
68
|
+
stop();
|
|
69
|
+
await child.exited.catch(() => undefined);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export const runOperator: OperatorRun = async (operation, request, credentials, signal) => {
|
|
74
|
+
if (signal?.aborted) throw new OperatorStartError();
|
|
75
|
+
const gateway = await requireGateway().catch(() => { throw new OperatorStartError(); });
|
|
76
|
+
return invokeOperator([gateway, "operator", operation], request, credentials, signal);
|
|
77
|
+
};
|
package/src/pr-github-schema.ts
CHANGED
|
@@ -17,6 +17,8 @@ export class PrReadError extends Error {
|
|
|
17
17
|
|
|
18
18
|
const id = Type.Integer({ minimum: 1, maximum: Number.MAX_SAFE_INTEGER });
|
|
19
19
|
export const sha = Type.String({ pattern: "^(?:[0-9a-f]{40}|[0-9a-f]{64})$" });
|
|
20
|
+
// PR intake accepts SHA-1 only; general GitHub reads also accept SHA-256.
|
|
21
|
+
export const sha40 = Type.String({ pattern: "^[0-9a-f]{40}$" });
|
|
20
22
|
const nullableText = Type.Union([Type.String(), Type.Null()]);
|
|
21
23
|
const user = Type.Union([Type.Object({
|
|
22
24
|
login: Type.String({ pattern: "^[a-zA-Z0-9][a-zA-Z0-9-]*(\\[bot\\])?$", maxLength: 100 }),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { Type, type Static } from "@sinclair/typebox/type";
|
|
3
3
|
import type { StorePort } from "./contracts";
|
|
4
|
-
import { PrReadError, parseWire } from "./pr-github-schema";
|
|
4
|
+
import { PrReadError, parseWire, sha40 as sha } from "./pr-github-schema";
|
|
5
5
|
import { inspectIntakeComment, publishIntakeComment } from "./pr-intake-comment";
|
|
6
6
|
import { applyIntakeFix, parseIntakeFix, reconcileIntakeFix } from "./pr-intake-fix";
|
|
7
7
|
import { inspectIntakeMerge, mergeIntakePull } from "./pr-intake-github";
|
|
@@ -12,7 +12,6 @@ import type { ReviewRound } from "./pr-intake-review";
|
|
|
12
12
|
// allow: SIZE_OK - This state machine owns the PR-wide ledger and its single write fence.
|
|
13
13
|
const maxHeads = 3;
|
|
14
14
|
const rank = { review: 0, fix: 1, merge: 2 } as const;
|
|
15
|
-
const sha = Type.String({ pattern: "^[a-f0-9]{40}$" });
|
|
16
15
|
const hash = Type.String({ pattern: "^[a-f0-9]{64}$" });
|
|
17
16
|
const nonempty = Type.String({ minLength: 1 });
|
|
18
17
|
const materialSchema = Type.Object({ digest: hash, baseRef: nonempty, baseSha: sha, headRef: nonempty });
|
package/src/pr-intake-comment.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { Type, type Static, type TSchema } from "@sinclair/typebox/type";
|
|
3
3
|
import { parsePrRef } from "./pr-github";
|
|
4
|
-
import { loginSchema, parseWire, PrReadError } from "./pr-github-schema";
|
|
4
|
+
import { loginSchema, parseWire, PrReadError, sha40 as sha } from "./pr-github-schema";
|
|
5
5
|
import { openIntakeGitHubSession, queryIntakeGitHub, type IntakeMergeIdentity } from "./pr-intake-github";
|
|
6
6
|
import { intakeEvidenceDeadlineMs } from "./pr-intake-material";
|
|
7
7
|
|
|
8
8
|
const id = Type.String({ pattern: "^[A-Za-z0-9_+/=-]{1,256}$" });
|
|
9
|
-
const sha = Type.String({ pattern: "^[0-9a-f]{40}$" });
|
|
10
9
|
const databaseId = Type.Integer({ minimum: 1, maximum: Number.MAX_SAFE_INTEGER });
|
|
11
10
|
const user = Type.Object({ login: loginSchema.properties.login, databaseId });
|
|
12
11
|
const actor = Type.Object({ login: Type.String(), databaseId: Type.Optional(Type.Union([databaseId, Type.Null()])) });
|
package/src/pr-intake-fix.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { Type, type Static } from "@sinclair/typebox/type";
|
|
3
|
-
import { parseWire, PrReadError } from "./pr-github-schema";
|
|
3
|
+
import { parseWire, PrReadError, sha40 as oid } from "./pr-github-schema";
|
|
4
4
|
import { openIntakeGitHubSession, queryIntakeGitHub, type IntakeRepositoryIdentity } from "./pr-intake-github";
|
|
5
5
|
import {
|
|
6
6
|
intakeEvidenceDeadlineMs, IntakeMaterialError, readIntakeDiff, readIntakePullIdentity, serializeIntakeDiff,
|
|
@@ -10,7 +10,6 @@ import { openIntakeTree, readIntakeBlob } from "./pr-intake-tree";
|
|
|
10
10
|
|
|
11
11
|
const maxSnippet = 8 * 1024;
|
|
12
12
|
const maxSource = 96 * 1024;
|
|
13
|
-
const oid = Type.String({ pattern: "^[0-9a-f]{40}$" });
|
|
14
13
|
const id = Type.String({ minLength: 1, maxLength: 256, pattern: "^[A-Za-z0-9_+=/-]+$" });
|
|
15
14
|
const fix = Type.Object({
|
|
16
15
|
path: Type.String({ minLength: 1, maxLength: 256 }),
|
package/src/pr-intake-github.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { execFile } from "node:child_process";
|
|
2
2
|
import { Type, type Static, type TSchema } from "@sinclair/typebox/type";
|
|
3
3
|
import { parsePrRef, readGitHubApi } from "./pr-github";
|
|
4
|
-
import { PrReadError, checkPageSchema, loginSchema, pages, parseWire, statusSchema } from "./pr-github-schema";
|
|
4
|
+
import { PrReadError, checkPageSchema, loginSchema, pages, parseWire, sha40 as sha, statusSchema } from "./pr-github-schema";
|
|
5
5
|
|
|
6
6
|
// allow: SIZE_OK — One wire adapter; preflight and the single mutation share the authenticated session.
|
|
7
7
|
const id = Type.Integer({ minimum: 1, maximum: Number.MAX_SAFE_INTEGER });
|
|
8
|
-
const sha = Type.String({ pattern: "^[0-9a-f]{40}$" });
|
|
9
8
|
const nodeId = Type.String({ pattern: "^[A-Za-z0-9_+/=-]{1,256}$" });
|
|
10
9
|
const utcTimestamp = Type.String({ pattern: "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(\\.[0-9]{3})?Z$" });
|
|
11
10
|
const actor = Type.Object({ id, login: loginSchema.properties.login, type: Type.Literal("User") });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Type, type Static } from "@sinclair/typebox/type";
|
|
2
2
|
import { parsePrRef } from "./pr-github";
|
|
3
|
-
import { loginSchema, parseWire, PrReadError } from "./pr-github-schema";
|
|
3
|
+
import { loginSchema, parseWire, PrReadError, sha40 as sha } from "./pr-github-schema";
|
|
4
4
|
import { openIntakeGitHubSession, type IntakeRepositoryIdentity } from "./pr-intake-github";
|
|
5
5
|
import { openIntakeTree, readIntakeBlob } from "./pr-intake-tree";
|
|
6
6
|
|
|
@@ -11,7 +11,6 @@ const maxReviewBlobBytes = 96 * 1024;
|
|
|
11
11
|
export const intakeEvidenceDeadlineMs = 90_000;
|
|
12
12
|
const count = Type.Integer({ minimum: 0, maximum: Number.MAX_SAFE_INTEGER });
|
|
13
13
|
const id = Type.Integer({ minimum: 1, maximum: Number.MAX_SAFE_INTEGER });
|
|
14
|
-
const sha = Type.String({ pattern: "^[0-9a-f]{40}$" });
|
|
15
14
|
const login = loginSchema.properties.login;
|
|
16
15
|
const actor = Type.Object({ id, login, type: Type.Literal("User") });
|
|
17
16
|
const repo = Type.Object({ id, full_name: Type.String({ minLength: 3, maxLength: 140 }), owner: Type.Object({ id, login }) });
|
package/src/pr-intake-tree.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { Type, type Static } from "@sinclair/typebox/type";
|
|
3
|
-
import { PrReadError } from "./pr-github-schema";
|
|
3
|
+
import { PrReadError, sha40 as sha } from "./pr-github-schema";
|
|
4
4
|
import type { openIntakeGitHubSession } from "./pr-intake-github";
|
|
5
5
|
|
|
6
6
|
type Session = Awaited<ReturnType<typeof openIntakeGitHubSession>>;
|
|
7
|
-
const sha = Type.String({ pattern: "^[0-9a-f]{40}$" });
|
|
8
7
|
const entry = Type.Object({ mode: Type.String(), type: Type.String(), sha, path: Type.String() });
|
|
9
8
|
const commit = Type.Object({ sha, tree: Type.Object({ sha }) });
|
|
10
9
|
const tree = Type.Object({ sha, truncated: Type.Literal(false), tree: Type.Array(entry) });
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { LaneModel } from "./contracts";
|
|
2
|
+
import { acceptsRestrictedModelSelector, isLaneModel } from "./lane-models";
|
|
3
|
+
|
|
4
|
+
const inferenceApis = new Set(["openai-completions", "openai-responses", "openai-codex-responses",
|
|
5
|
+
"azure-openai-responses", "anthropic-messages"]);
|
|
6
|
+
|
|
7
|
+
/** A tool-free inference API, not an external agent harness. */
|
|
8
|
+
export function isPrReviewInferenceModel(model: unknown): boolean {
|
|
9
|
+
return typeof model === "object" && model !== null
|
|
10
|
+
&& "api" in model && typeof model.api === "string" && inferenceApis.has(model.api)
|
|
11
|
+
&& "provider" in model && typeof model.provider === "string" && model.provider !== "gitlab-duo"
|
|
12
|
+
&& (!("transport" in model) || model.transport !== "pi-native");
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** New selections must be exact, unique chat models in the native available catalogue. */
|
|
16
|
+
export function prReviewModelChoices<T>(catalog: readonly T[]): (T & LaneModel)[] {
|
|
17
|
+
const choices = new Map<string, (T & LaneModel) | undefined>();
|
|
18
|
+
for (const model of catalog) {
|
|
19
|
+
if (!isLaneModel(model)) continue;
|
|
20
|
+
const key = JSON.stringify([model.provider, model.id]);
|
|
21
|
+
// Track rejected entries too: another row with this identity is ambiguous.
|
|
22
|
+
const allowed = !choices.has(key) && isPrReviewInferenceModel(model)
|
|
23
|
+
&& acceptsRestrictedModelSelector(model)
|
|
24
|
+
&& (!("kind" in model) || model.kind === undefined || model.kind === "chat");
|
|
25
|
+
choices.set(key, allowed ? model : undefined);
|
|
26
|
+
}
|
|
27
|
+
return [...choices.values()].filter(model => model !== undefined);
|
|
28
|
+
}
|
package/src/result-attachment.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { isAbsolute } from "node:path";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
3
|
import type { ExtensionAPI } from "@oh-my-pi/pi-coding-agent";
|
|
4
4
|
import { Type } from "@sinclair/typebox";
|
|
5
5
|
import type { Inbound } from "./contracts";
|
|
@@ -7,11 +7,17 @@ import type { Inbound } from "./contracts";
|
|
|
7
7
|
const MAX_RESULT_ATTACHMENT_BYTES = 8 * 1024 * 1024;
|
|
8
8
|
export const RESULT_ATTACH_TOOL = "result_attach";
|
|
9
9
|
|
|
10
|
-
export interface
|
|
10
|
+
export interface ResultAttachmentSnapshot {
|
|
11
11
|
readonly name: string;
|
|
12
|
-
readonly
|
|
12
|
+
readonly size: number;
|
|
13
|
+
readonly sha256: string;
|
|
14
|
+
readonly snapshotId: string;
|
|
15
|
+
readonly fileIdentity: string;
|
|
13
16
|
}
|
|
14
17
|
|
|
18
|
+
// Read-only compatibility with output rows persisted before the native spool.
|
|
19
|
+
export type ResultAttachmentPayload = ResultAttachmentSnapshot | { readonly name: string; readonly data: string };
|
|
20
|
+
|
|
15
21
|
interface NativeSession {
|
|
16
22
|
readonly sessionId: string;
|
|
17
23
|
readonly sessionFile: string;
|
|
@@ -59,89 +65,64 @@ export function isOriginalAttachmentMessage({ id, messageId, route }: Inbound):
|
|
|
59
65
|
: `${route.platform}:${route.accountId}:${route.channelId}:${messageId}:original`);
|
|
60
66
|
}
|
|
61
67
|
|
|
62
|
-
|
|
63
|
-
const delta = relative(root, file);
|
|
64
|
-
return delta === "" || delta !== ".." && !delta.startsWith(`..${sep}`) && !isAbsolute(delta);
|
|
65
|
-
}
|
|
68
|
+
const binary = fileURLToPath(new URL(`../gateway/bin/omp-gateway-${process.platform}-${process.arch}`, import.meta.url));
|
|
66
69
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
readonly
|
|
70
|
-
readonly
|
|
71
|
-
|
|
70
|
+
type StageCommand =
|
|
71
|
+
| { readonly action: "stage"; readonly stateDir: string; readonly cwd: string; readonly path: string; readonly privatePaths: readonly string[] }
|
|
72
|
+
| { readonly action: "discard"; readonly stateDir: string; readonly snapshotId: string }
|
|
73
|
+
| { readonly action: "prune"; readonly stateDir: string };
|
|
74
|
+
|
|
75
|
+
function runStage(command: StageCommand): unknown {
|
|
72
76
|
try {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
if (realpathSync(root) !== root) throw new ResultAttachmentError("The canonical workspace root has changed");
|
|
76
|
-
const originalRoot = lstatSync(root, { bigint: true });
|
|
77
|
-
const file = resolve(root, path);
|
|
78
|
-
const name = basename(file);
|
|
79
|
-
if (Buffer.byteLength(name) > 180 || !/^[\p{L}\p{N}\p{M}_. -]+$/u.test(name))
|
|
80
|
-
throw new ResultAttachmentError("The result attachment has an unsupported filename");
|
|
81
|
-
const privateEntries = scope.privatePaths.map(privatePath => {
|
|
82
|
-
let canonical = resolve(privatePath);
|
|
83
|
-
try {
|
|
84
|
-
canonical = realpathSync(canonical);
|
|
85
|
-
return { canonical, stat: lstatSync(canonical, { bigint: true }) };
|
|
86
|
-
} catch (error) {
|
|
87
|
-
if (!(error instanceof Error && "code" in error && error.code === "ENOENT")) throw error;
|
|
88
|
-
return { canonical };
|
|
89
|
-
}
|
|
77
|
+
const child = Bun.spawnSync([binary, "__stage-result-attachment"], {
|
|
78
|
+
env: {}, stdin: Buffer.from(JSON.stringify(command)), stdout: "pipe", stderr: "ignore", timeout: 5_000,
|
|
90
79
|
});
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
throw new ResultAttachmentError("Private state cannot be sent as a result attachment");
|
|
98
|
-
// Also compare filesystem identities (e.g. case-insensitive volumes).
|
|
99
|
-
let current = root;
|
|
100
|
-
for (const part of ["", ...path.split("/")]) {
|
|
101
|
-
current = resolve(current, part);
|
|
102
|
-
const stat = lstatSync(current, { bigint: true });
|
|
103
|
-
if (stat.isSymbolicLink()) throw new ResultAttachmentError("Result attachment paths cannot follow links");
|
|
104
|
-
if (privateEntries.some(entry => entry.stat?.dev === stat.dev && entry.stat.ino === stat.ino))
|
|
105
|
-
throw new ResultAttachmentError("Private state cannot be sent as a result attachment");
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
checkPrivate();
|
|
109
|
-
if (realpathSync(file) !== file) throw new ResultAttachmentError("Result attachment paths cannot follow links");
|
|
110
|
-
// lstat and the identity checks pin the observed directory entry to the
|
|
111
|
-
// descriptor. Nonblocking open cannot hang if it is replaced with a FIFO.
|
|
112
|
-
const initial = lstatSync(file, { bigint: true });
|
|
113
|
-
if (!initial.isFile() || initial.nlink !== 1n)
|
|
114
|
-
throw new ResultAttachmentError("A result attachment must be a regular file without hard links");
|
|
115
|
-
const fd = openSync(file, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
|
116
|
-
try {
|
|
117
|
-
const same = (stat: typeof initial) => stat.isFile() && stat.nlink === 1n
|
|
118
|
-
&& stat.dev === initial.dev && stat.ino === initial.ino && stat.size === initial.size
|
|
119
|
-
&& stat.mtimeNs === initial.mtimeNs && stat.ctimeNs === initial.ctimeNs;
|
|
120
|
-
if (!same(fstatSync(fd, { bigint: true }))) throw new ResultAttachmentError("The attachment changed before staging");
|
|
121
|
-
if (initial.size < 1n || initial.size > MAX_RESULT_ATTACHMENT_BYTES)
|
|
122
|
-
throw new ResultAttachmentError("Result attachments must be nonempty and at most 8 MiB");
|
|
123
|
-
const bytes = Buffer.allocUnsafe(Number(initial.size));
|
|
124
|
-
let offset = 0;
|
|
125
|
-
while (offset < bytes.length) {
|
|
126
|
-
const count = readSync(fd, bytes, offset, bytes.length - offset, offset);
|
|
127
|
-
if (!count) break;
|
|
128
|
-
offset += count;
|
|
129
|
-
}
|
|
130
|
-
if (offset !== bytes.length || !same(fstatSync(fd, { bigint: true }))
|
|
131
|
-
|| realpathSync(file) !== file || !same(lstatSync(file, { bigint: true }))) {
|
|
132
|
-
throw new ResultAttachmentError("The attachment changed during staging");
|
|
133
|
-
}
|
|
134
|
-
checkPrivate();
|
|
135
|
-
return { name, data: bytes.toString("base64") };
|
|
136
|
-
} finally {
|
|
137
|
-
closeSync(fd);
|
|
138
|
-
}
|
|
80
|
+
if (child.exitCode !== 0 || child.stdout.length > 4_096)
|
|
81
|
+
throw new ResultAttachmentError("The native result attachment helper did not complete");
|
|
82
|
+
const response = asRecord(JSON.parse(child.stdout.toString("utf8")));
|
|
83
|
+
if (response?.ok === true) return response.value;
|
|
84
|
+
if (response?.ok === false && typeof response.error === "string") throw new ResultAttachmentError(response.error);
|
|
85
|
+
throw new ResultAttachmentError("The native result attachment helper returned no receipt");
|
|
139
86
|
} catch (error) {
|
|
140
87
|
if (error instanceof ResultAttachmentError) throw error;
|
|
141
|
-
|
|
88
|
+
// Do not attach an exception that could include the command's private paths.
|
|
89
|
+
throw new ResultAttachmentError("The native result attachment helper is unavailable");
|
|
142
90
|
}
|
|
143
91
|
}
|
|
144
92
|
|
|
93
|
+
export function isResultAttachmentSnapshot(value: unknown): value is ResultAttachmentSnapshot {
|
|
94
|
+
const snapshot = asRecord(value);
|
|
95
|
+
return snapshot !== null && Object.keys(snapshot).length === 5 &&
|
|
96
|
+
typeof snapshot.name === "string" && validPath(snapshot.name) && Buffer.byteLength(snapshot.name) <= 180 &&
|
|
97
|
+
/^[\p{L}\p{N}\p{M}_. -]+$/u.test(snapshot.name) &&
|
|
98
|
+
typeof snapshot.size === "number" && Number.isSafeInteger(snapshot.size) &&
|
|
99
|
+
snapshot.size > 0 && snapshot.size <= MAX_RESULT_ATTACHMENT_BYTES &&
|
|
100
|
+
typeof snapshot.sha256 === "string" && /^[a-f0-9]{64}$/.test(snapshot.sha256) &&
|
|
101
|
+
typeof snapshot.snapshotId === "string" && /^[a-f0-9]{32}$/.test(snapshot.snapshotId) &&
|
|
102
|
+
typeof snapshot.fileIdentity === "string" && /^\d+:\d+$/.test(snapshot.fileIdentity);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** The helper publishes a private immutable snapshot before queue admission. */
|
|
106
|
+
export function stageResultAttachment(path: string, scope: {
|
|
107
|
+
readonly stateDir: string;
|
|
108
|
+
readonly cwd: string;
|
|
109
|
+
readonly privatePaths: readonly string[];
|
|
110
|
+
}): ResultAttachmentSnapshot {
|
|
111
|
+
if (!validPath(path)) throw new ResultAttachmentError("Use a literal, non-hidden workspace-relative file path");
|
|
112
|
+
const receipt = runStage({ action: "stage", ...scope, path });
|
|
113
|
+
if (!isResultAttachmentSnapshot(receipt) || receipt.name !== path.split("/").at(-1))
|
|
114
|
+
throw new ResultAttachmentError("The native result attachment receipt does not match the request");
|
|
115
|
+
return receipt;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function discardResultAttachment(stateDir: string, snapshotId: string): void {
|
|
119
|
+
runStage({ action: "discard", stateDir, snapshotId });
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function pruneResultAttachments(stateDir: string): void {
|
|
123
|
+
runStage({ action: "prune", stateDir });
|
|
124
|
+
}
|
|
125
|
+
|
|
145
126
|
export function registerResultAttach(pi: ExtensionAPI, submit?: (intent: ResultAttachmentIntent) => string): void {
|
|
146
127
|
pi.on("tool_call", (event, ctx) => {
|
|
147
128
|
if (event.toolName === RESULT_ATTACH_TOOL && ctx.agent.kind !== "main")
|