|
| 1 | +#!/usr/bin/env node |
| 2 | +// Builds a synthetic "future" OpenClaw package from a real packed one: the same |
| 3 | +// declarations plus a new ./plugin-sdk entrypoint and new chunks that expose |
| 4 | +// SDK retirement replacements the source release does not, through the |
| 5 | +// declaration shapes a later release could use. Retirement qualification of |
| 6 | +// the result must match the full type check (0.4.5 computes it), and the |
| 7 | +// publish path must stay within its memory budget without any per-release data. |
| 8 | +// |
| 9 | +// node scripts/make-future-openclaw-fixture.mjs --from <unpacked openclaw package> --out <dir> [--computed-names] |
| 10 | +// |
| 11 | +// --computed-names adds a mapped type whose keys come from a template literal, |
| 12 | +// so one replacement name is computed rather than spelled. Certificates cannot |
| 13 | +// decide such a name; it exercises the exact type-checked fallback. |
| 14 | +import { cp, mkdir, readFile, writeFile } from "node:fs/promises"; |
| 15 | +import path from "node:path"; |
| 16 | +import { parseArgs } from "node:util"; |
| 17 | + |
| 18 | +const { values } = parseArgs({ |
| 19 | + options: { from: { type: "string" }, out: { type: "string" }, "computed-names": { type: "boolean" } }, |
| 20 | +}); |
| 21 | +if (!values.from || !values.out) { |
| 22 | + console.error("Usage: node scripts/make-future-openclaw-fixture.mjs --from <unpacked openclaw package> --out <dir> [--computed-names]"); |
| 23 | + process.exit(2); |
| 24 | +} |
| 25 | +const from = path.resolve(values.from); |
| 26 | +const out = path.resolve(values.out); |
| 27 | +await mkdir(out, { recursive: true }); |
| 28 | +await cp(from, out, { recursive: true }); |
| 29 | +const packageJson = JSON.parse(await readFile(path.join(out, "package.json"), "utf8")); |
| 30 | +packageJson.version = `${packageJson.version.replace(/-.*$/, "")}-future.1`; |
| 31 | + |
| 32 | +const files = { |
| 33 | + // A rolled-up chunk in the style of the real ones: minified export aliases. |
| 34 | + "dist/future-sessions-Fz9.d.ts": `import { t as FutureLinkStore } from "./future-links-Ab1.js"; |
| 35 | +//#region src/sessions/future-session-manager.d.ts |
| 36 | +/** A session manager whose persistence is asynchronous. */ |
| 37 | +declare class SessionManager { |
| 38 | + static openAsync(sessionKey: string): Promise<SessionManager>; |
| 39 | + appendMessageAsync(message: unknown): Promise<void>; |
| 40 | + persistAsync(): Promise<void>; |
| 41 | + get links(): FutureLinkStore; |
| 42 | +} |
| 43 | +interface FutureWorkspaceGrant { |
| 44 | + acquireManagedWorkspaceAsync(owner: string): Promise<{ assertCurrentAsync(): Promise<void>; release(): void }>; |
| 45 | +} |
| 46 | +type FutureVersioned<Version extends 1 | 2 = 1> = Version extends 2 ? { statusAsync(): Promise<string> } : { selectV1(): void }; |
| 47 | +type FutureBox<T> = { value: T; cancelAsync(): Promise<void> }; |
| 48 | +declare const { readAsync, writeBack }: { readAsync: () => Promise<FutureRecorder>; writeBack: () => void }; |
| 49 | +interface FutureRecorder { recordTurnAsync(): Promise<void> } |
| 50 | +declare enum FutureMode { selectAsync = "selectAsync" } |
| 51 | +//#endregion |
| 52 | +export { SessionManager as a, FutureWorkspaceGrant as i, FutureVersioned as n, FutureBox as o, readAsync as r, FutureMode as s, writeBack as u }; |
| 53 | +`, |
| 54 | + "dist/future-links-Ab1.d.ts": `//#region src/sessions/future-links.d.ts |
| 55 | +interface FutureLinkStore { |
| 56 | + listLinksAsync(): Promise<string[]>; |
| 57 | + linkAsync(id: string): Promise<void>; |
| 58 | + unlinkAsync(id: string): Promise<void>; |
| 59 | +} |
| 60 | +//#endregion |
| 61 | +export { FutureLinkStore as t }; |
| 62 | +`, |
| 63 | + // An entry with no export declarations: every declaration is exported. |
| 64 | + "dist/plugin-sdk/future-runtime.d.ts": `import { a as SessionManager, i as FutureWorkspaceGrant, n as FutureVersioned, o as FutureBox, r as readAsync, s as FutureMode } from "../future-sessions-Fz9.js"; |
| 65 | +type FutureRuntime = { |
| 66 | + sessions: typeof SessionManager; |
| 67 | + workspace: FutureWorkspaceGrant; |
| 68 | + versioned: FutureVersioned<2>; |
| 69 | + boxed: FutureBox<string>; |
| 70 | + read: typeof readAsync; |
| 71 | + mode: typeof FutureMode; |
| 72 | +}; |
| 73 | +declare function createFutureRuntime(): FutureRuntime; |
| 74 | +declare global { |
| 75 | + interface FutureGlobalHook { resolveConfigAsync(): Promise<unknown> } |
| 76 | +} |
| 77 | +export declare const futureHook: FutureGlobalHook; |
| 78 | +`, |
| 79 | + "dist/plugin-sdk/future-default.d.ts": `declare const runtime: { openAsync(): Promise<void> }; |
| 80 | +export default runtime; |
| 81 | +export { a as SessionManager } from "../future-sessions-Fz9.js"; |
| 82 | +`, |
| 83 | +}; |
| 84 | +if (values["computed-names"]) { |
| 85 | + files["dist/plugin-sdk/future-computed.d.ts"] = `type Verbs = "unlink" | "personalStatus"; |
| 86 | +export type FutureComputed = { [K in Verbs as \`\${K}Async\`]: () => Promise<void> }; |
| 87 | +`; |
| 88 | + packageJson.exports["./plugin-sdk/future-computed"] = { types: "./dist/plugin-sdk/future-computed.d.ts", default: "./dist/plugin-sdk/future-computed.js" }; |
| 89 | +} |
| 90 | +for (const [name, source] of Object.entries(files)) await writeFile(path.join(out, name), source); |
| 91 | +packageJson.exports["./plugin-sdk/future-runtime"] = { types: "./dist/plugin-sdk/future-runtime.d.ts", default: "./dist/plugin-sdk/future-runtime.js" }; |
| 92 | +packageJson.exports["./plugin-sdk/future-default"] = { types: "./dist/plugin-sdk/future-default.d.ts", default: "./dist/plugin-sdk/future-default.js" }; |
| 93 | +await writeFile(path.join(out, "package.json"), `${JSON.stringify(packageJson, null, 2)}\n`); |
| 94 | +console.log(`${out}: openclaw@${packageJson.version}`); |
0 commit comments