mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-11-05 23:37:25 +00:00
feat(coding-agent): remove the experimental server stack and the client, protocol, and server packages
Deletes packages/client, packages/protocol (CBOR codec), packages/server, coding-agent's src/experimental (except source-resolver.ts, which source runs still preload), src/cli/experimental, src/client, the example plugin, and their tests. coding-agent no longer depends on @earendil-works/chord. The installer lock drops esbuild, so its platform-package sanity check goes too.
This commit is contained in:
parent
2ee5c1e56d
commit
7472cda0d6
161 changed files with 32 additions and 21561 deletions
|
|
@ -1,8 +1,6 @@
|
|||
import { Client } from "@earendil-works/pi-client";
|
||||
import { createAssistantMessageEventStream, Type } from "@earendil-works/pi-ai";
|
||||
import { complete, getModel, getProviders, streamSimple } from "@earendil-works/pi-ai/compat";
|
||||
import { Agent, streamProxy } from "@earendil-works/pi-agent-core";
|
||||
import { decodeCbor, encodeCbor, PROTOCOL_VERSION } from "@earendil-works/pi-protocol";
|
||||
|
||||
// Keep this entry browser-safe. It is bundled by scripts/check-browser-smoke.mjs
|
||||
// to catch accidental Node-only runtime imports in browser-facing package exports.
|
||||
|
|
@ -21,7 +19,4 @@ console.log(
|
|||
typeof stream.push,
|
||||
agent.hasQueuedMessages(),
|
||||
typeof streamProxy,
|
||||
typeof Client,
|
||||
PROTOCOL_VERSION,
|
||||
decodeCbor(encodeCbor({ browser: true })),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -16,11 +16,6 @@ const banner = {
|
|||
js: 'import { createRequire as __piCreateRequire } from "node:module"; const require = __piCreateRequire(import.meta.url);',
|
||||
};
|
||||
const allowedExternalPackages = new Set([
|
||||
"@earendil-works/chord",
|
||||
"@earendil-works/chord/bundler",
|
||||
"@earendil-works/chord/context",
|
||||
"@earendil-works/chord/delta",
|
||||
"@earendil-works/chord/node",
|
||||
"@silvia-odwyer/photon-node",
|
||||
"jiti",
|
||||
// Optional native accelerators. Their callers fall back to JavaScript when absent.
|
||||
|
|
@ -86,7 +81,7 @@ function commonBuildOptions() {
|
|||
banner,
|
||||
bundle: true,
|
||||
define: { PI_BUNDLED_NODE: "true" },
|
||||
external: ["@earendil-works/chord", "@silvia-odwyer/photon-node"],
|
||||
external: ["@silvia-odwyer/photon-node"],
|
||||
format: "esm",
|
||||
legalComments: "none",
|
||||
logLevel: "warning",
|
||||
|
|
|
|||
|
|
@ -1,36 +1,13 @@
|
|||
import { execFileSync } from "node:child_process";
|
||||
import { existsSync, mkdtempSync, readdirSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
|
||||
export const codingAgentName = "@earendil-works/pi-coding-agent";
|
||||
const developmentPackages = new Set(["pi-client", "pi-protocol", "pi-server"].map((name) => `@earendil-works/${name}`));
|
||||
|
||||
function checkInstalledPackages(nodeModules, seen = new Set()) {
|
||||
if (!existsSync(nodeModules)) return;
|
||||
const directories = readdirSync(nodeModules)
|
||||
.filter((name) => !name.startsWith("."))
|
||||
.flatMap((name) => name.startsWith("@")
|
||||
? readdirSync(join(nodeModules, name)).map((child) => join(nodeModules, name, child))
|
||||
: [join(nodeModules, name)]);
|
||||
for (const directory of directories) {
|
||||
if (!existsSync(join(directory, "package.json"))) continue;
|
||||
const path = realpathSync(directory);
|
||||
if (seen.has(path)) continue;
|
||||
seen.add(path);
|
||||
const manifest = JSON.parse(readFileSync(join(path, "package.json"), "utf8"));
|
||||
if (developmentPackages.has(manifest.name)) throw new Error(`${manifest.name} must not be installed: ${path}`);
|
||||
checkInstalledPackages(join(path, "node_modules"), seen);
|
||||
}
|
||||
}
|
||||
|
||||
export function smokeTestCodingAgent(directory, runtime = process.execPath) {
|
||||
checkInstalledPackages(join(directory, "node_modules"));
|
||||
const packageDir = join(directory, "node_modules", codingAgentName);
|
||||
const manifest = JSON.parse(readFileSync(join(packageDir, "package.json"), "utf8"));
|
||||
for (const path of ["dist/client", "dist/experimental", "dist/cli/experimental", "dist/bundle/client.js", "dist/bundle/coordinator.js"]) {
|
||||
if (existsSync(join(packageDir, path))) throw new Error(`Published package contains development-only code: ${path}`);
|
||||
}
|
||||
const home = mkdtempSync(join(tmpdir(), "pi-coding-agent-smoke-home-"));
|
||||
const entry = join(directory, "coding-agent-smoke.mjs");
|
||||
const env = {
|
||||
|
|
@ -54,9 +31,6 @@ import { createAgentSession, SessionManager, ModelRuntime } from "${codingAgentN
|
|||
assert.equal(typeof createAgentSession, "function");
|
||||
assert.equal(typeof SessionManager.inMemory, "function");
|
||||
assert.equal(typeof ModelRuntime.create, "function");
|
||||
for (const subpath of ["/client", "/experimental/plugin"]) {
|
||||
assert.throws(() => import.meta.resolve("${codingAgentName}" + subpath), /not exported|not defined|Cannot find|cannot find/);
|
||||
}
|
||||
`);
|
||||
execFileSync(runtime, [entry], { cwd: directory, env, stdio: ["inherit", "pipe", "pipe"], timeout: 30_000 });
|
||||
for (const cli of new Set([manifest.bin.pi, "dist/cli.js"])) {
|
||||
|
|
|
|||
|
|
@ -7,8 +7,6 @@ import { installConsumer } from "./local-package-install.mjs";
|
|||
import { produceArtifactSet } from "./package-artifacts.mjs";
|
||||
import { codingAgentName, smokeTestCodingAgent } from "./coding-agent-smoke.mjs";
|
||||
|
||||
const devPackages = ["pi-client", "pi-protocol", "pi-server"].map((name) => `@earendil-works/${name}`);
|
||||
|
||||
function writePackage(directory, manifest, files) {
|
||||
mkdirSync(directory, { recursive: true });
|
||||
writeFileSync(join(directory, "package.json"), `${JSON.stringify(manifest, null, "\t")}\n`);
|
||||
|
|
@ -18,86 +16,48 @@ function writePackage(directory, manifest, files) {
|
|||
}
|
||||
}
|
||||
|
||||
function createFixture(t, { importServer = false, declareServer = false } = {}) {
|
||||
function createFixture(t, { importUndeclared = false } = {}) {
|
||||
const temporaryRoot = mkdtempSync(join(tmpdir(), "pi-coding-agent-smoke-test-"));
|
||||
t.after(() => rmSync(temporaryRoot, { recursive: true, force: true }));
|
||||
const root = join(temporaryRoot, "fixture with spaces");
|
||||
const repoRoot = join(root, "repo");
|
||||
mkdirSync(repoRoot, { recursive: true });
|
||||
writeFileSync(join(repoRoot, "package.json"), '{"name":"fixture","private":true}\n');
|
||||
const packageNames = [codingAgentName, ...devPackages];
|
||||
for (const name of packageNames) {
|
||||
const isAgent = name === codingAgentName;
|
||||
writePackage(
|
||||
join(repoRoot, "packages", name.split("/")[1]),
|
||||
{
|
||||
name,
|
||||
version: "1.0.0",
|
||||
type: "module",
|
||||
main: "./dist/index.js",
|
||||
types: "./dist/index.d.ts",
|
||||
exports: isAgent
|
||||
? {
|
||||
".": { types: "./dist/index.d.ts", import: "./dist/index.js" },
|
||||
"./client": { source: "./src/client/index.ts" },
|
||||
"./experimental/plugin": { source: "./src/experimental/plugin.ts" },
|
||||
}
|
||||
: { ".": { types: "./dist/index.d.ts", import: "./dist/index.js" } },
|
||||
files: ["dist"],
|
||||
...(isAgent
|
||||
? {
|
||||
bin: { pi: "dist/bundle/cli.js" },
|
||||
...(declareServer ? { dependencies: { "@earendil-works/pi-server": "1.0.0" } } : {}),
|
||||
devDependencies: Object.fromEntries(devPackages.map((packageName) => [packageName, "1.0.0"])),
|
||||
}
|
||||
: {}),
|
||||
},
|
||||
{
|
||||
"dist/index.js": isAgent
|
||||
? `${importServer ? 'import "@earendil-works/pi-server";' : ""}
|
||||
writePackage(
|
||||
join(repoRoot, "packages", codingAgentName.split("/")[1]),
|
||||
{
|
||||
name: codingAgentName,
|
||||
version: "1.0.0",
|
||||
type: "module",
|
||||
main: "./dist/index.js",
|
||||
types: "./dist/index.d.ts",
|
||||
exports: { ".": { types: "./dist/index.d.ts", import: "./dist/index.js" } },
|
||||
files: ["dist"],
|
||||
bin: { pi: "dist/bundle/cli.js" },
|
||||
},
|
||||
{
|
||||
"dist/index.js": `${importUndeclared ? 'import "@earendil-works/undeclared";' : ""}
|
||||
export function createAgentSession() {}
|
||||
export class SessionManager { static inMemory() {} }
|
||||
export class ModelRuntime { static create() {} }
|
||||
`
|
||||
: "export {};\n",
|
||||
"dist/index.d.ts": "export {};\n",
|
||||
...(isAgent
|
||||
? {
|
||||
"dist/cli.js": 'console.log("1.0.0");\n',
|
||||
"dist/bundle/cli.js": 'console.log("1.0.0");\n',
|
||||
}
|
||||
: {}),
|
||||
},
|
||||
);
|
||||
}
|
||||
`,
|
||||
"dist/index.d.ts": "export {};\n",
|
||||
"dist/cli.js": 'console.log("1.0.0");\n',
|
||||
"dist/bundle/cli.js": 'console.log("1.0.0");\n',
|
||||
},
|
||||
);
|
||||
const artifactSet = produceArtifactSet({ build: false, outDir: join(root, "artifacts"), repoRoot, source: null });
|
||||
const directory = join(root, "consumer");
|
||||
installConsumer({ artifactSet, directory, packageNames: [codingAgentName] });
|
||||
return directory;
|
||||
}
|
||||
|
||||
test("accepts a valid coding-agent package and rejects development-only packages and files", (t) => {
|
||||
const directory = createFixture(t);
|
||||
smokeTestCodingAgent(directory);
|
||||
|
||||
const nested = join(directory, "node_modules", codingAgentName, "node_modules/@earendil-works/pi-server");
|
||||
mkdirSync(nested, { recursive: true });
|
||||
writeFileSync(join(nested, "package.json"), JSON.stringify({ name: "@earendil-works/pi-server", version: "1.0.0" }));
|
||||
assert.throws(() => smokeTestCodingAgent(directory), /pi-server must not be installed/);
|
||||
rmSync(nested, { recursive: true });
|
||||
|
||||
const experimental = join(directory, "node_modules", codingAgentName, "dist/experimental");
|
||||
mkdirSync(experimental);
|
||||
assert.throws(() => smokeTestCodingAgent(directory), /contains development-only code/);
|
||||
test("accepts a valid coding-agent package", (t) => {
|
||||
smokeTestCodingAgent(createFixture(t));
|
||||
});
|
||||
|
||||
// #9132: smoke-test the public SDK, not just a bundled CLI that hides missing imports.
|
||||
test("fails when the SDK imports an undeclared server despite a working CLI", (t) => {
|
||||
const directory = createFixture(t, { importServer: true });
|
||||
assert.throws(() => smokeTestCodingAgent(directory), /Cannot find package '@earendil-works\/pi-server'/);
|
||||
});
|
||||
|
||||
test("fails if a development-only dependency is added back to the published dependency tree", (t) => {
|
||||
const directory = createFixture(t, { declareServer: true });
|
||||
assert.throws(() => smokeTestCodingAgent(directory), /pi-server must not be installed/);
|
||||
test("fails when the SDK imports an undeclared package despite a working CLI", (t) => {
|
||||
const directory = createFixture(t, { importUndeclared: true });
|
||||
assert.throws(() => smokeTestCodingAgent(directory), /Cannot find package '@earendil-works\/undeclared'/);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ const internalPackageNames = new Set(["@earendil-works/chord"]);
|
|||
const installPackageName = "@earendil-works/pi-coding-agent-install";
|
||||
const allowedInstallScriptPackages = new Map([
|
||||
["@google/genai@2.21.0", "preinstall is a no-op in the published package"],
|
||||
["esbuild@0.28.2", "postinstall selects and verifies the platform-specific esbuild binary"],
|
||||
["protobufjs@7.6.6", "postinstall only warns about protobufjs version scheme mismatches"],
|
||||
]);
|
||||
|
||||
|
|
@ -364,12 +363,6 @@ function validateGeneratedFiles(installerPackageJson, installLock, internalNames
|
|||
}
|
||||
}
|
||||
|
||||
const platformPackageCount = Object.values(installLock.packages).filter((entry) => entry.os || entry.cpu || entry.libc)
|
||||
.length;
|
||||
if (platformPackageCount === 0) {
|
||||
errors.push("no platform-specific optional dependency entries found");
|
||||
}
|
||||
|
||||
if (errors.length > 0) {
|
||||
throw new Error(`Generated installer lock failed validation:\n${errors.map((error) => ` - ${error}`).join("\n")}`);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -305,10 +305,6 @@ async function runBuild(bundle) {
|
|||
"packages/ai",
|
||||
"--workspace",
|
||||
"packages/agent",
|
||||
"--workspace",
|
||||
"packages/protocol",
|
||||
"--workspace",
|
||||
"packages/client",
|
||||
],
|
||||
},
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue