chore(integration): snapshot local main worktree

This commit is contained in:
inman
2026-08-31 10:23:21 +08:00
parent 48a9189939
commit 33fb31fb28
116 changed files with 8108 additions and 3026 deletions

View File

@@ -1,3 +1,4 @@
import { accessSync, constants } from 'node:fs';
import path from 'node:path';
import type { AgentBrowserModule } from '../agent-browser';
import { CodingAttachmentStore } from '../coding-projects/attachment-store';
@@ -10,6 +11,7 @@ import {
} from '../coding-projects/project-store';
import { CodingConversationService } from '../coding-runtime/conversation-service';
import { PiManagedExtensionHost } from '../coding-runtime/pi/extension-host';
import { PiAgentServerProcess } from '../coding-runtime/pi/agent-server-process';
import { PiManagedInputRevisionCoordinator } from '../coding-runtime/pi/managed-input-revision';
import { PiProductTools } from '../coding-runtime/pi/product-tools';
import {
@@ -31,12 +33,15 @@ import {
refreshCodingProviderCredential,
} from './coding-provider-auth';
import { createCodingProductHost, type CodingProductComposition } from './coding-product-services';
import { archivePiConversationSession } from '../coding-runtime/pi/resource-loader';
import { resolveLegacyProjectModel } from '../coding-projects/legacy-v1';
import {
archivePiConversationSession,
getPiManagedPaths,
} from '../coding-runtime/pi/resource-loader';
export interface CodingCompositionPaths {
executablePath: string;
cliPath: string;
serverPath: string;
userDataDir: string;
bundledSkillsDir: string;
}
@@ -50,14 +55,51 @@ export interface CreateCodingCompositionOptions {
acquireBackgroundLease?(lease: { id: string; kind: 'coding-run' }): () => void;
}
type PiWorkerExecutableProbe = (candidate: string) => boolean;
function canExecute(candidate: string): boolean {
try {
accessSync(candidate, constants.X_OK);
return true;
} catch {
return false;
}
}
export function resolvePiWorkerExecutablePath(
executablePath: string,
options: {
platform?: NodeJS.Platform;
canExecute?: PiWorkerExecutableProbe;
} = {},
): string {
if ((options.platform ?? process.platform) !== 'darwin') return executablePath;
// The product binary remains a Foreground LaunchServices app even in Node mode.
// Electron's generic Helper is LSUIElement=true, so workers stay out of the Dock.
const executableName = path.basename(executablePath);
const helperExecutablePath = path.resolve(
path.dirname(executablePath),
'..',
'Frameworks',
`${executableName} Helper.app`,
'Contents',
'MacOS',
`${executableName} Helper`,
);
return (options.canExecute ?? canExecute)(helperExecutablePath)
? helperExecutablePath
: executablePath;
}
export function resolveCodingPiRuntimePaths(input: {
isPackaged: boolean;
resourcesPath: string;
appPath: string;
executablePath: string;
}): Pick<CodingCompositionPaths, 'executablePath' | 'cliPath'> {
}): Pick<CodingCompositionPaths, 'executablePath' | 'cliPath' | 'serverPath'> {
return {
executablePath: input.executablePath,
executablePath: resolvePiWorkerExecutablePath(input.executablePath),
cliPath: input.isPackaged
? path.join(input.resourcesPath, 'pi-runtime', 'dist', 'cli.js')
: path.join(
@@ -68,6 +110,9 @@ export function resolveCodingPiRuntimePaths(input: {
'dist',
'cli.js',
),
serverPath: input.isPackaged
? path.join(input.resourcesPath, 'resources', 'pi-agent-server.mjs')
: path.join(input.appPath, 'resources', 'pi-agent-server.mjs'),
};
}
@@ -100,12 +145,20 @@ export function createCodingComposition(
});
const revisions = new PiManagedInputRevisionCoordinator();
const processBudget = new PiProcessBudget();
const agentServer = new PiAgentServerProcess({
executablePath: options.paths.executablePath,
serverPath: options.paths.serverPath,
runtimeRoot: path.dirname(path.dirname(options.paths.cliPath)),
configDir: getPiManagedPaths(options.paths.userDataDir).configDir,
});
const loadProviderInput = async () => ({
accounts: await getProviderService().listAccounts(),
modelSummaries: [],
});
const workerPool = new PiWorkerPool({
processBudget,
processMode: 'shared',
maxIdle: 8,
revisionCoordinator: revisions,
openWorker: createPiManagedWorkerOpener({
registry,
@@ -115,6 +168,7 @@ export function createCodingComposition(
bundledSkillsDir: options.paths.bundledSkillsDir,
loadProviderInput,
resolveCredential: resolvePiProviderCredentialFromSecretStore,
createProcess: (processOptions) => agentServer.createWorker(processOptions),
...(getLocalProxyCredential
? { getLocalProxyCredential: async () => getLocalProxyCredential() }
: {}),
@@ -138,7 +192,6 @@ export function createCodingComposition(
const subagents = new PiSubagentScheduler({
openChild: childOpener,
processBudget,
reclaimProcessCapacity: (signal) => workerPool.reclaimIdleWorker(signal),
});
const runtime = new PiConversationRuntime({
pool: workerPool,
@@ -164,12 +217,6 @@ export function createCodingComposition(
: {}),
});
const projects = new CodingProjectService(projectStore, {
migration: {
resolveLegacyModel: async ({ legacyModel }) => resolveLegacyProjectModel(
legacyModel,
await getProviderService().listAccounts(),
),
},
createConversationStore: conversationStoreForProject,
onResourcesChanged: async (project) => {
runtime.markResourcesStale();
@@ -215,10 +262,15 @@ export function createCodingComposition(
await Promise.allSettled(conversationIds.map((conversationId) => (
runtime.dispose(conversationId, reason)
)));
await agentServer.stop();
},
async shutdown() {
await subagents.close();
await runtime.shutdown();
try {
await runtime.shutdown();
} finally {
await agentServer.stop();
}
},
};
}