omp-superagent 0.1.18 → 0.1.19
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/docs/OPERATIONS.en.md +127 -30
- package/docs/OPERATIONS.md +114 -27
- package/docs/design/execution.md +90 -23
- package/docs/design/messaging.md +34 -2
- package/docs/releases/0.1.19.md +10 -0
- package/gateway/bin/omp-gateway-darwin-arm64 +0 -0
- package/gateway/bin/omp-gateway-darwin-x64 +0 -0
- package/gateway/bin/omp-gateway-linux-arm64 +0 -0
- package/gateway/bin/omp-gateway-linux-x64 +0 -0
- package/host-owner/bin/omp-host-owner-darwin-arm64 +0 -0
- package/host-owner/bin/omp-host-owner-darwin-x64 +0 -0
- package/host-owner/bin/omp-host-owner-linux-arm64 +0 -0
- package/host-owner/bin/omp-host-owner-linux-x64 +0 -0
- package/package.json +1 -1
- package/skills/head/SKILL.md +4 -3
- package/skills/head/references/model-selection.md +8 -22
- package/skills/head/references/routing.md +19 -11
- package/skills/lane/SKILL.md +24 -76
- package/skills/lane/references/workflow.md +7 -94
- package/src/cli.ts +36 -16
- package/src/config/config.ts +6 -2
- package/src/contracts.ts +20 -4
- package/src/extension.ts +10 -5
- package/src/host-extension.ts +76 -8
- package/src/lane/lane-report.ts +1 -1
- package/src/lane/lane-rows.ts +2 -1
- package/src/lane-extension.ts +4 -21
- package/src/messaging/result-attachment.ts +77 -19
- package/src/messaging/written-directives.ts +56 -0
- package/src/omp/exit-record.ts +27 -0
- package/src/omp/host-protocol.ts +20 -0
- package/src/omp/host.ts +73 -20
- package/src/omp/installed-omp.ts +15 -12
- package/src/omp/managed-super.ts +135 -65
- package/src/routing/topic-request.ts +7 -4
- package/src/runtime/controller.ts +512 -165
- package/src/runtime/inbound-attachments.ts +70 -0
- package/src/runtime/local-host-fence.ts +85 -0
- package/src/runtime/model-journal.ts +14 -9
- package/src/runtime/native-frames.ts +5 -1
- package/src/runtime/result-attachments.ts +151 -24
- package/src/runtime/worker-result-download.ts +36 -0
- package/src/storage/store.ts +79 -26
- package/src/worker/worker-checkout.ts +89 -9
- package/src/worker/worker-destination.ts +8 -7
- package/src/worker/worker-doctor.ts +29 -9
- package/src/worker/worker-enrollment.ts +44 -12
- package/src/worker/worker-git-startup.ts +157 -0
- package/src/worker/worker-host.ts +16 -26
- package/src/worker/worker-ledger.ts +42 -18
- package/src/worker/worker-placement-intent.ts +13 -0
- package/src/worker/worker-placement.ts +204 -28
- package/src/worker/worker-profile.ts +18 -65
- package/src/worker/worker-project-startup.ts +106 -0
- package/src/worker/worker-registration.ts +85 -30
- package/src/worker/worker-repository.ts +55 -6
- package/src/worker/worker-request.ts +13 -6
- package/src/worker/worker-result-attachments.ts +185 -0
- package/src/worker/worker-result-wire.ts +12 -0
- package/src/worker/worker-service.ts +51 -23
- package/src/worker/worker-trust.ts +19 -4
- package/src/worker/worker-wire.ts +47 -14
- package/upstream/super.json +2 -3
package/src/omp/managed-super.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Database } from "bun:sqlite";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
2
3
|
import { lstatSync, readFileSync, realpathSync } from "node:fs";
|
|
3
4
|
import { chmod, link, lstat, mkdir, mkdtemp, readFile, readdir, realpath, rename, rm, writeFile } from "node:fs/promises";
|
|
4
5
|
import { dirname, isAbsolute, join, resolve, sep } from "node:path";
|
|
@@ -10,6 +11,10 @@ import type { NativeProfile, NativeProfileBinding, NativeProfilePaths } from "./
|
|
|
10
11
|
const projectRoot = fileURLToPath(new URL("../../", import.meta.url));
|
|
11
12
|
const ownership = "omp-superagent-managed-ulw-v1";
|
|
12
13
|
const hash = /^[0-9a-f]{40,64}$/;
|
|
14
|
+
const sha256 = /^[0-9a-f]{64}$/;
|
|
15
|
+
const releaseVersion = /^v(\d+\.\d+\.\d+)$/;
|
|
16
|
+
const officialReleaseApi = "https://api.github.com/repos/dbc-hbin/omp-superkit/releases/latest";
|
|
17
|
+
const releaseTokenEnv = "OMP_SUPERAGENT_SUPERKIT_GITHUB_TOKEN";
|
|
13
18
|
export const MANAGED_ULW_ENV = "OMP_SUPERAGENT_MANAGED_ULW_PATH";
|
|
14
19
|
// Only explicitly injected fixtures propagate. The per-Host revision marker above
|
|
15
20
|
// is informational: a new lane must resolve the current active revision afresh.
|
|
@@ -18,23 +23,25 @@ export const MANAGED_ULW_FIXTURE_ROOT_ENV = "OMP_SUPERAGENT_TEST_MANAGED_ULW_ROO
|
|
|
18
23
|
|
|
19
24
|
export interface UlwManifest {
|
|
20
25
|
repository: string;
|
|
21
|
-
|
|
26
|
+
releaseApi: string;
|
|
22
27
|
directory: string;
|
|
23
28
|
checkIntervalMs: number;
|
|
24
29
|
commandTimeoutMs: number;
|
|
25
30
|
probeTimeoutMs: number;
|
|
26
|
-
materialize: string | null;
|
|
27
31
|
}
|
|
28
32
|
export interface ManagedUlwStatus {
|
|
29
33
|
revision: string | null;
|
|
34
|
+
releaseTag: string | null;
|
|
30
35
|
packagePath: string | null;
|
|
31
36
|
upstreamRevision: string | null;
|
|
37
|
+
upstreamReleaseTag: string | null;
|
|
32
38
|
checkedAt: string | null;
|
|
33
39
|
error: string | null;
|
|
34
40
|
updating: boolean;
|
|
35
41
|
injected?: boolean;
|
|
36
42
|
}
|
|
37
|
-
|
|
43
|
+
type ReleaseIdentity = { readonly tag: string; readonly sha256: string };
|
|
44
|
+
interface ActiveRevision { revision: string; repository: string; branch?: string; release?: ReleaseIdentity; preparedAt: string }
|
|
38
45
|
interface PackageManifest {
|
|
39
46
|
name?: string;
|
|
40
47
|
omp?: { extensions?: string[]; skills?: string[]; [key: string]: unknown };
|
|
@@ -57,11 +64,10 @@ function matchesUlwRepository(previous: string, current: string): boolean {
|
|
|
57
64
|
|
|
58
65
|
export function readUlwManifest(manifestPath = join(projectRoot, "upstream/super.json")): UlwManifest {
|
|
59
66
|
const value = JSON.parse(readFileSync(manifestPath, "utf8")) as UlwManifest;
|
|
60
|
-
if (!value.repository || value.
|
|
67
|
+
if (!value.repository || typeof value.releaseApi !== "string" || !/^https?:\/\//.test(value.releaseApi) || !value.directory ||
|
|
61
68
|
!Number.isSafeInteger(value.checkIntervalMs) || value.checkIntervalMs < 60_000 ||
|
|
62
69
|
!Number.isSafeInteger(value.commandTimeoutMs) || value.commandTimeoutMs < 1_000 ||
|
|
63
|
-
!Number.isSafeInteger(value.probeTimeoutMs) || value.probeTimeoutMs < 1_000
|
|
64
|
-
!(value.materialize === null || typeof value.materialize === "string"))
|
|
70
|
+
!Number.isSafeInteger(value.probeTimeoutMs) || value.probeTimeoutMs < 1_000)
|
|
65
71
|
throw new Error("Invalid managed ULW manifest");
|
|
66
72
|
return value;
|
|
67
73
|
}
|
|
@@ -78,10 +84,20 @@ function assertOwned(root: string): void {
|
|
|
78
84
|
function readActive(root: string): ActiveRevision | null {
|
|
79
85
|
try {
|
|
80
86
|
const value = JSON.parse(readFileSync(join(root, "active.json"), "utf8")) as ActiveRevision;
|
|
81
|
-
if (!hash.test(value.revision) || !value.repository ||
|
|
87
|
+
if (!hash.test(value.revision) || !value.repository ||
|
|
88
|
+
(value.release === undefined ? !value.branch
|
|
89
|
+
: !value.release || typeof value.release.tag !== "string" || !releaseVersion.test(value.release.tag) ||
|
|
90
|
+
typeof value.release.sha256 !== "string" || !sha256.test(value.release.sha256)))
|
|
91
|
+
throw new Error("Invalid managed ULW active pointer");
|
|
82
92
|
return value;
|
|
83
93
|
} catch (error) { if ((error as NodeJS.ErrnoException).code === "ENOENT") return null; throw error; }
|
|
84
94
|
}
|
|
95
|
+
function installationDirectory(root: string, active: ActiveRevision): string {
|
|
96
|
+
return active.release ? join(root, "releases", active.release.sha256) : join(root, "revisions", active.revision);
|
|
97
|
+
}
|
|
98
|
+
function sameRelease(a?: ReleaseIdentity, b?: ReleaseIdentity): boolean {
|
|
99
|
+
return a?.tag === b?.tag && a?.sha256 === b?.sha256;
|
|
100
|
+
}
|
|
85
101
|
export function readManagedUlwPackage(packagePath: string) {
|
|
86
102
|
if (!isAbsolute(packagePath)) throw new Error("Managed ULW package must have an absolute path");
|
|
87
103
|
const canonical = realpathSync(packagePath);
|
|
@@ -109,9 +125,10 @@ export function activeManagedUlw(options: ManagedUlwOptions = {}): string {
|
|
|
109
125
|
}
|
|
110
126
|
const active = readActive(root);
|
|
111
127
|
if (!active) throw new Error("Mandatory managed ULW is not installed; run bun run prepare:ulw");
|
|
112
|
-
const revisionRoot =
|
|
128
|
+
const revisionRoot = installationDirectory(root, active);
|
|
113
129
|
const provenance = JSON.parse(readFileSync(join(revisionRoot, "provenance.json"), "utf8")) as ActiveRevision;
|
|
114
|
-
if (provenance.revision !== active.revision || provenance.repository !== active.repository
|
|
130
|
+
if (provenance.revision !== active.revision || provenance.repository !== active.repository ||
|
|
131
|
+
!sameRelease(provenance.release, active.release))
|
|
115
132
|
throw new Error("Managed ULW provenance does not match its active pointer");
|
|
116
133
|
return validateManagedUlwPackage(join(revisionRoot, "package"));
|
|
117
134
|
}
|
|
@@ -121,8 +138,9 @@ export function managedUlwStatus(options: ManagedUlwOptions = {}): ManagedUlwSta
|
|
|
121
138
|
try { saved = JSON.parse(readFileSync(join(root, "status.json"), "utf8")); }
|
|
122
139
|
catch (error) { if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error; }
|
|
123
140
|
const active = readActive(root);
|
|
124
|
-
return { revision: active?.revision ?? null,
|
|
125
|
-
|
|
141
|
+
return { revision: active?.revision ?? null, releaseTag: active?.release?.tag ?? null,
|
|
142
|
+
packagePath: active ? join(installationDirectory(root, active), "package") : null,
|
|
143
|
+
upstreamRevision: saved.upstreamRevision ?? null, upstreamReleaseTag: saved.upstreamReleaseTag ?? null, checkedAt: saved.checkedAt ?? null,
|
|
126
144
|
error: saved.error ?? null, updating: saved.updating ?? false };
|
|
127
145
|
}
|
|
128
146
|
async function atomicJson(path: string, value: unknown): Promise<void> {
|
|
@@ -156,12 +174,70 @@ async function initialize(root: string): Promise<void> {
|
|
|
156
174
|
}
|
|
157
175
|
assertOwned(root);
|
|
158
176
|
}
|
|
159
|
-
async function run(args: string[], cwd: string, timeout: number,
|
|
160
|
-
|
|
177
|
+
async function run(args: string[], cwd: string, timeout: number, options: {
|
|
178
|
+
readonly env?: Record<string, string>;
|
|
179
|
+
readonly input?: Blob;
|
|
180
|
+
} = {}): Promise<string> {
|
|
181
|
+
const { [releaseTokenEnv]: _token, ...publicEnv } = process.env;
|
|
182
|
+
const child = Bun.spawn(args, { cwd, env: options.env ?? publicEnv, stdin: options.input ?? "ignore",
|
|
183
|
+
stdout: "pipe", stderr: "pipe", timeout, killSignal: "SIGKILL" });
|
|
161
184
|
const [stdout, stderr, exit] = await Promise.all([new Response(child.stdout).text(), new Response(child.stderr).text(), child.exited]);
|
|
162
185
|
if (exit !== 0) throw new Error(`${args[0]} ${args[1] ?? ""} failed (${exit}): ${stderr.slice(-2000)}`);
|
|
163
186
|
return stdout.trim();
|
|
164
187
|
}
|
|
188
|
+
function download(url: string, options: {
|
|
189
|
+
readonly cwd: string;
|
|
190
|
+
readonly timeout: number;
|
|
191
|
+
readonly args: readonly string[];
|
|
192
|
+
readonly authorization?: Blob;
|
|
193
|
+
}): Promise<string> {
|
|
194
|
+
// Send authenticated metadata requests directly: never forward the header on
|
|
195
|
+
// redirects or expose it in curl's arguments or environment.
|
|
196
|
+
const route = options.authorization ? ["--header", "@-"]
|
|
197
|
+
: ["--location", "--max-redirs", "5", "--proto-redir", "=https"];
|
|
198
|
+
return run(["curl", "--disable", "--fail", "--silent", "--show-error", "--proto", "=http,https",
|
|
199
|
+
...route, ...options.args, "--", url], options.cwd, options.timeout, { input: options.authorization });
|
|
200
|
+
}
|
|
201
|
+
function record(value: unknown): value is Record<string, unknown> {
|
|
202
|
+
return typeof value === "object" && value !== null;
|
|
203
|
+
}
|
|
204
|
+
async function latestRelease(manifest: UlwManifest, root: string): Promise<ReleaseIdentity & { readonly url: string }> {
|
|
205
|
+
const token = manifest.releaseApi === officialReleaseApi ? process.env[releaseTokenEnv] : undefined;
|
|
206
|
+
// Keep GitHub's access token opaque; only reject characters unsafe in an HTTP header.
|
|
207
|
+
if (token && /[\p{Cc}\s]/u.test(token)) throw new Error(`Invalid ${releaseTokenEnv}`);
|
|
208
|
+
const data: unknown = JSON.parse(await download(manifest.releaseApi, {
|
|
209
|
+
cwd: root, timeout: manifest.commandTimeoutMs,
|
|
210
|
+
args: ["--header", "Accept: application/vnd.github+json", "--max-filesize", "2097152"],
|
|
211
|
+
authorization: token ? new Blob([`Authorization: Bearer ${token}\n`]) : undefined,
|
|
212
|
+
}));
|
|
213
|
+
const tag = record(data) ? data.tag_name : undefined;
|
|
214
|
+
const version = typeof tag === "string" ? releaseVersion.exec(tag)?.[1] : undefined;
|
|
215
|
+
if (!record(data) || typeof tag !== "string" || !version || data.draft !== false || data.prerelease !== false ||
|
|
216
|
+
!Array.isArray(data.assets)) throw new Error("ULW upstream did not advertise a stable GitHub release");
|
|
217
|
+
const assets: unknown[] = data.assets;
|
|
218
|
+
const matches = assets.filter(asset => record(asset) && asset.name === `omp-superkit-${version}.zip`);
|
|
219
|
+
const [asset] = matches;
|
|
220
|
+
const digest = record(asset) && typeof asset.digest === "string" ? /^sha256:([0-9a-f]{64})$/.exec(asset.digest)?.[1] : undefined;
|
|
221
|
+
if (matches.length !== 1 || !digest || !record(asset) || typeof asset.browser_download_url !== "string" ||
|
|
222
|
+
!/^https?:\/\//.test(asset.browser_download_url))
|
|
223
|
+
throw new Error(`Superkit release ${tag} does not have a unique packaged ZIP with a SHA-256 digest`);
|
|
224
|
+
return { tag, sha256: digest, url: asset.browser_download_url };
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
async function unpackRelease(release: ReleaseIdentity & { readonly url: string }, stage: string, timeout: number): Promise<string> {
|
|
228
|
+
const zip = join(stage, "release.zip");
|
|
229
|
+
await download(release.url, { cwd: stage, timeout, args: ["--max-filesize", "67108864", "--output", zip] });
|
|
230
|
+
const checksum = createHash("sha256");
|
|
231
|
+
for await (const chunk of Bun.file(zip).stream()) checksum.update(chunk);
|
|
232
|
+
if (checksum.digest("hex") !== release.sha256) throw new Error(`Superkit release ${release.tag} ZIP failed SHA-256 verification`);
|
|
233
|
+
const unpacked = join(stage, "unpacked");
|
|
234
|
+
await mkdir(unpacked, { mode: 0o700 });
|
|
235
|
+
await run(["unzip", "-q", zip, "-d", unpacked], stage, timeout);
|
|
236
|
+
const packagePath = join(unpacked, "omp-superkit");
|
|
237
|
+
if (!(await lstat(packagePath)).isDirectory()) throw new Error("Superkit ZIP does not contain an omp-superkit package directory");
|
|
238
|
+
await checkLinks(packagePath);
|
|
239
|
+
return packagePath;
|
|
240
|
+
}
|
|
165
241
|
async function immutableTree(directory: string): Promise<void> {
|
|
166
242
|
for (const entry of await readdir(directory, { withFileTypes: true })) {
|
|
167
243
|
const path = join(directory, entry.name);
|
|
@@ -188,7 +264,7 @@ async function probe(packagePath: string, stage: string, manifest: UlwManifest):
|
|
|
188
264
|
XDG_DATA_HOME: join(home, "data"), XDG_CACHE_HOME: join(home, "cache"), CI: "true", NO_COLOR: "1" };
|
|
189
265
|
if (process.env.PI_NATIVES_DIR) env.PI_NATIVES_DIR = process.env.PI_NATIVES_DIR;
|
|
190
266
|
await run([process.execPath, fileURLToPath(new URL("../managed-super-probe.ts", import.meta.url)), packagePath],
|
|
191
|
-
home, manifest.probeTimeoutMs, env);
|
|
267
|
+
home, manifest.probeTimeoutMs, { env });
|
|
192
268
|
}
|
|
193
269
|
|
|
194
270
|
export type ManagedUlwLaunchInput = {
|
|
@@ -201,7 +277,7 @@ export type ManagedUlwLaunchInput = {
|
|
|
201
277
|
commandArgs: string[];
|
|
202
278
|
/** Exact native OMP argv, including the original command's flags and generated Host args; no executable prefix. */
|
|
203
279
|
launchArgs: string[];
|
|
204
|
-
worker?: Pick<WorkerHostProfile, "extensionPaths" | "memory">;
|
|
280
|
+
worker?: Pick<WorkerHostProfile, "extensionPaths" | "memory" | "trustedWorkspaceRoot">;
|
|
205
281
|
expectedNativeProfile?: NativeProfile;
|
|
206
282
|
};
|
|
207
283
|
type ManagedUlwLaunchOptions = Omit<ManagedUlwLaunchInput, "managedUlwPath"> & {
|
|
@@ -349,11 +425,11 @@ export async function managedUlwLaunchComposition(input: ManagedUlwLaunchInput):
|
|
|
349
425
|
}
|
|
350
426
|
|
|
351
427
|
async function workerLaunchComposition(input: ManagedUlwLaunchInput & {
|
|
352
|
-
worker:
|
|
428
|
+
worker: NonNullable<ManagedUlwLaunchInput["worker"]>;
|
|
353
429
|
}): Promise<ManagedUlwLaunchComposition> {
|
|
354
|
-
const { assertWorkerWorkspaceStartup } = await import("../worker/worker-
|
|
430
|
+
const { assertWorkerWorkspaceStartup } = await import("../worker/worker-project-startup");
|
|
355
431
|
const { homedir } = await import("node:os");
|
|
356
|
-
assertWorkerWorkspaceStartup(input.cwd, homedir());
|
|
432
|
+
assertWorkerWorkspaceStartup(input.cwd, homedir(), input.worker.trustedWorkspaceRoot);
|
|
357
433
|
const { parseNativeLaunch } = await import("./native-launch-profile");
|
|
358
434
|
const parsed = await parseNativeLaunch(input.launchArgs);
|
|
359
435
|
if (!parsed.noExtensions || !parsed.noLsp)
|
|
@@ -581,65 +657,60 @@ export async function updateManagedUlw(options: ManagedUlwOptions = {}): Promise
|
|
|
581
657
|
}
|
|
582
658
|
let stage: string | undefined;
|
|
583
659
|
let upstreamRevision: string | null = null;
|
|
660
|
+
let upstreamReleaseTag: string | null = null;
|
|
584
661
|
const checkedAt = new Date().toISOString();
|
|
585
662
|
try {
|
|
586
663
|
await atomicJson(join(root, "status.json"), { ...managedUlwStatus(options), checkedAt, updating: true, error: null });
|
|
587
664
|
const git = (args: string[], cwd = root) => run(["git", "-c", "core.hooksPath=/dev/null", ...args], cwd, manifest.commandTimeoutMs,
|
|
588
|
-
{ PATH: process.env.PATH ?? "/usr/bin:/bin", HOME: root, USERPROFILE: root,
|
|
589
|
-
GIT_TERMINAL_PROMPT: "0", GIT_CONFIG_NOSYSTEM: "1", GIT_CONFIG_GLOBAL: "/dev/null" });
|
|
590
|
-
const remote = await git(["ls-remote", "--symref", manifest.repository, "HEAD"]);
|
|
591
|
-
const branch = /^ref: (refs\/heads\/[^\s]+)\s+HEAD$/m.exec(remote)?.[1];
|
|
592
|
-
upstreamRevision = /^([0-9a-f]{40,64})\s+HEAD$/m.exec(remote)?.[1] ?? null;
|
|
593
|
-
if (!branch || !upstreamRevision) throw new Error("ULW upstream did not advertise an unambiguous default branch and HEAD commit");
|
|
665
|
+
{ env: { PATH: process.env.PATH ?? "/usr/bin:/bin", HOME: root, USERPROFILE: root,
|
|
666
|
+
GIT_TERMINAL_PROMPT: "0", GIT_CONFIG_NOSYSTEM: "1", GIT_CONFIG_GLOBAL: "/dev/null" } });
|
|
594
667
|
const active = readActive(root);
|
|
595
|
-
let nextActive: ActiveRevision | undefined;
|
|
596
668
|
if (active && !matchesUlwRepository(active.repository, manifest.repository))
|
|
597
669
|
throw new Error("Managed ULW source repository changed; explicit operator reconciliation required");
|
|
598
|
-
|
|
670
|
+
const latest = await latestRelease(manifest, root);
|
|
671
|
+
const release = { tag: latest.tag, sha256: latest.sha256 };
|
|
672
|
+
upstreamReleaseTag = release.tag;
|
|
673
|
+
const ref = `refs/tags/${release.tag}`;
|
|
674
|
+
const remote = await git(["ls-remote", "--exit-code", "--", manifest.repository, ref, `${ref}^{}`]);
|
|
675
|
+
const refs = new Map(remote.split("\n").map(line => {
|
|
676
|
+
const [revision, name] = line.split("\t");
|
|
677
|
+
return [name, revision];
|
|
678
|
+
}));
|
|
679
|
+
const revision = refs.get(`${ref}^{}`) ?? refs.get(ref);
|
|
680
|
+
if (!revision || !hash.test(revision)) throw new Error(`ULW upstream did not advertise Git tag ${release.tag}`);
|
|
681
|
+
upstreamRevision = revision;
|
|
682
|
+
let selected: ActiveRevision;
|
|
683
|
+
if (active?.revision === upstreamRevision && sameRelease(active.release, release)) {
|
|
599
684
|
activeManagedUlw(options);
|
|
685
|
+
selected = active;
|
|
600
686
|
} else {
|
|
601
|
-
const
|
|
687
|
+
const provenance: ActiveRevision = { revision: upstreamRevision, repository: manifest.repository, release, preparedAt: new Date().toISOString() };
|
|
688
|
+
const revisionRoot = installationDirectory(root, provenance);
|
|
602
689
|
let preparedRepository: string | undefined;
|
|
603
690
|
try {
|
|
604
|
-
const
|
|
605
|
-
if (
|
|
691
|
+
const prepared = JSON.parse(await readFile(join(revisionRoot, "provenance.json"), "utf8")) as ActiveRevision;
|
|
692
|
+
if (prepared.revision !== upstreamRevision || !matchesUlwRepository(prepared.repository, manifest.repository) ||
|
|
693
|
+
!sameRelease(prepared.release, release))
|
|
606
694
|
throw new Error("Existing immutable ULW revision has different provenance");
|
|
607
695
|
validateManagedUlwPackage(join(revisionRoot, "package"));
|
|
608
|
-
preparedRepository =
|
|
696
|
+
preparedRepository = prepared.repository;
|
|
609
697
|
} catch (error) { if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error; }
|
|
610
|
-
const provenance: ActiveRevision = { revision: upstreamRevision, repository: manifest.repository, branch, preparedAt: new Date().toISOString() };
|
|
611
698
|
stage = await mkdtemp(join(root, ".stage-"));
|
|
612
|
-
const source = join(stage, preparedRepository ? "ancestry" : "source");
|
|
613
699
|
const distribution = join(stage, "distribution");
|
|
614
700
|
const packagePath = join(preparedRepository ? revisionRoot : distribution, "package");
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
await git(["
|
|
620
|
-
await git(["
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
await git(["checkout", "--detach", upstreamRevision], source);
|
|
624
|
-
if (await git(["rev-parse", "HEAD"], source) !== upstreamRevision) throw new Error("ULW checkout revision changed while staging");
|
|
625
|
-
}
|
|
626
|
-
if (active) {
|
|
627
|
-
try { await git(["merge-base", "--is-ancestor", active.revision, upstreamRevision], source); }
|
|
701
|
+
// Use Git only to verify ancestry, never to supply the installed files.
|
|
702
|
+
if (active && active.revision !== upstreamRevision) {
|
|
703
|
+
const ancestry = join(stage, "ancestry");
|
|
704
|
+
await git(["init", "--bare", ancestry]);
|
|
705
|
+
await git(["fetch", "--no-tags", "--", manifest.repository, ref], ancestry);
|
|
706
|
+
if (await git(["rev-parse", "FETCH_HEAD^{commit}"], ancestry) !== upstreamRevision)
|
|
707
|
+
throw new Error("ULW release tag changed during ancestry verification");
|
|
708
|
+
try { await git(["merge-base", "--is-ancestor", active.revision, upstreamRevision], ancestry); }
|
|
628
709
|
catch { throw new Error("ULW upstream update is not a provable fast-forward; explicit operator reconciliation required"); }
|
|
629
710
|
}
|
|
630
711
|
if (!preparedRepository) {
|
|
631
|
-
await
|
|
632
|
-
await
|
|
633
|
-
// Export tracked runtime/resources, not .git, dev node_modules, or the
|
|
634
|
-
// user's checkout. Gitlinks are only build inputs for materialization.
|
|
635
|
-
const archive = join(stage, "source.tar");
|
|
636
|
-
await git(["archive", "--format=tar", `--output=${archive}`, "HEAD"], source);
|
|
637
|
-
await run(["tar", "-xf", archive, "-C", packagePath], stage, manifest.commandTimeoutMs);
|
|
638
|
-
if (manifest.materialize) {
|
|
639
|
-
const materialize = resolve(source, manifest.materialize);
|
|
640
|
-
if (!materialize.startsWith(source + sep)) throw new Error("ULW materializer leaves source checkout");
|
|
641
|
-
await run([process.execPath, materialize, "--target-root", join(packagePath, "skills/frontend")], source, manifest.commandTimeoutMs);
|
|
642
|
-
}
|
|
712
|
+
await mkdir(distribution, { mode: 0o700 });
|
|
713
|
+
await rename(await unpackRelease(latest, stage, manifest.commandTimeoutMs), packagePath);
|
|
643
714
|
const pkgPath = join(packagePath, "package.json");
|
|
644
715
|
const pkg = JSON.parse(await readFile(pkgPath, "utf8")) as PackageManifest;
|
|
645
716
|
pkg.omp = { ...pkg.omp, skills: pkg.omp?.skills ?? ["./skills"] };
|
|
@@ -654,26 +725,25 @@ export async function updateManagedUlw(options: ManagedUlwOptions = {}): Promise
|
|
|
654
725
|
if (!preparedRepository) {
|
|
655
726
|
await writeFile(join(distribution, "provenance.json"), JSON.stringify(provenance, null, 2) + "\n", { mode: 0o444 });
|
|
656
727
|
await immutableTree(packagePath);
|
|
657
|
-
await mkdir(
|
|
728
|
+
await mkdir(dirname(revisionRoot), { recursive: true, mode: 0o700 });
|
|
658
729
|
await rename(distribution, revisionRoot);
|
|
659
730
|
}
|
|
660
|
-
|
|
731
|
+
selected = { ...provenance, repository: preparedRepository ?? provenance.repository };
|
|
661
732
|
}
|
|
662
733
|
// Finish fallible staging cleanup/status publication before committing the
|
|
663
734
|
// active pointer, so a failed preparation never reports a rollback after
|
|
664
735
|
// it has already activated a new revision.
|
|
665
736
|
if (stage) { await rm(stage, { recursive: true, force: true }); stage = undefined; }
|
|
666
|
-
await atomicJson(join(root, "status.json"), { upstreamRevision, checkedAt, updating: false, error: null });
|
|
667
|
-
const
|
|
668
|
-
|
|
669
|
-
packagePath: join(root, "revisions", selected.revision, "package"), upstreamRevision, checkedAt, updating: false, error: null };
|
|
737
|
+
await atomicJson(join(root, "status.json"), { upstreamRevision, upstreamReleaseTag, checkedAt, updating: false, error: null });
|
|
738
|
+
const result: ManagedUlwStatus = { revision: selected.revision, releaseTag: selected.release?.tag ?? null,
|
|
739
|
+
packagePath: join(installationDirectory(root, selected), "package"), upstreamRevision, upstreamReleaseTag, checkedAt, updating: false, error: null };
|
|
670
740
|
// The only activation write. Old immutable directories are never pruned:
|
|
671
741
|
// running Hosts and their native children may still import from them.
|
|
672
|
-
if (
|
|
742
|
+
if (selected !== active) await atomicJson(join(root, "active.json"), selected);
|
|
673
743
|
return result;
|
|
674
744
|
} catch (error) {
|
|
675
745
|
const message = error instanceof Error ? error.message : "Managed ULW update failed";
|
|
676
|
-
await atomicJson(join(root, "status.json"), { upstreamRevision, checkedAt, updating: false, error: message });
|
|
746
|
+
await atomicJson(join(root, "status.json"), { upstreamRevision, upstreamReleaseTag, checkedAt, updating: false, error: message });
|
|
677
747
|
throw new Error(`Managed ULW update failed; previous active revision retained: ${message}`, { cause: error });
|
|
678
748
|
} finally {
|
|
679
749
|
// Never delete an immutable revision or any path outside this invocation's
|
|
@@ -78,7 +78,8 @@ export function editsTopicPlacement(before: string, after: string): boolean {
|
|
|
78
78
|
export function existingWorkspace(path: string): string | null {
|
|
79
79
|
if (!isAbsolute(path)) return null;
|
|
80
80
|
try {
|
|
81
|
-
|
|
81
|
+
// Resolve symlinks before '..', just as chdir and the worker's Git process do.
|
|
82
|
+
const canonical = realpathSync.native(path);
|
|
82
83
|
return statSync(canonical).isDirectory() ? canonical : null;
|
|
83
84
|
} catch (error) {
|
|
84
85
|
if (!(error instanceof Error)) throw error;
|
|
@@ -115,11 +116,12 @@ export function namedWorkspaces(text: string, lanes: readonly Lane[], nameOnly =
|
|
|
115
116
|
}
|
|
116
117
|
|
|
117
118
|
/** Choose a single existing directory; conflicting evidence or explicit exclusions need clarification. */
|
|
118
|
-
export function inferredWorkspace(text: string, lanes: readonly Lane[], replied: string | null, threadWorkspace: string | null)
|
|
119
|
+
export function inferredWorkspace(text: string, lanes: readonly Lane[], replied: string | null, threadWorkspace: string | null) {
|
|
119
120
|
if (/\b(?:not|avoid|except|instead of|rather than|other than)\b|n['’]t\b|말고|대신|제외|빼고|아니라|아닌|(?:쓰|사용하)지\s*마/iu.test(text)) return null;
|
|
120
121
|
const candidates = namedWorkspaces(text, lanes);
|
|
121
122
|
const lineEnd = text.indexOf("\n");
|
|
122
|
-
const
|
|
123
|
+
const requested = lineEnd > 0 ? text.slice(0, lineEnd).trim() : null;
|
|
124
|
+
const path = requested === null ? null : existingWorkspace(requested);
|
|
123
125
|
if (path) candidates.add(path);
|
|
124
126
|
if (replied) candidates.add(replied);
|
|
125
127
|
if (!candidates.size && threadWorkspace) candidates.add(threadWorkspace);
|
|
@@ -127,5 +129,6 @@ export function inferredWorkspace(text: string, lanes: readonly Lane[], replied:
|
|
|
127
129
|
for (const lane of lanes) candidates.add(lane.cwd);
|
|
128
130
|
}
|
|
129
131
|
const [selected] = candidates;
|
|
130
|
-
return candidates.size === 1 && selected && existingWorkspace(selected) === selected
|
|
132
|
+
return candidates.size === 1 && selected && existingWorkspace(selected) === selected
|
|
133
|
+
? { cwd: selected, requested: selected === path ? requested ?? selected : selected } : null;
|
|
131
134
|
}
|