Merge remote-tracking branch 'origin/main' into feat/2072-ines-container
This commit is contained in:
@@ -123,6 +123,12 @@ export interface ProviderRequestActivitySnapshot {
|
||||
|
||||
/** Provider session bound to exactly one parsed artifact. */
|
||||
export interface AnalysisClient extends AnalysisOperationPort {
|
||||
/** Execute only if this operation can run without loading or starting a provider. */
|
||||
executeIfReady?(
|
||||
operation: AnalysisOperation,
|
||||
parameters: Readonly<Record<string, JsonValue>>,
|
||||
options?: ExecutionOptions,
|
||||
): Promise<Result<AnalysisExecution, AnalysisError> | undefined>;
|
||||
/** Retained token-verified process snapshots for dynamic providers this client started. */
|
||||
runtimeLineageSnapshots?(): readonly ProviderRuntimeLineageSnapshot[];
|
||||
/** Current provider work that may outlive a timed-out or cancelled caller. */
|
||||
|
||||
@@ -311,12 +311,15 @@ const detectArtifactFormat = async (
|
||||
if (lower.endsWith(".app")) return "app-pack";
|
||||
return zipPackageFormatForPath(lower) ?? "zip";
|
||||
}
|
||||
// Binary plists, including keyed archives, often use other extensions.
|
||||
if (observed.bytesRead === 8 && magic.equals(Buffer.from("bplist00")))
|
||||
return "plist";
|
||||
const named = namedArtifactFormat(lower);
|
||||
if (named !== undefined) return named;
|
||||
if (
|
||||
lower.endsWith(".pkg") &&
|
||||
observed.bytesRead >= 4 &&
|
||||
magic.subarray(0, 4).toString("ascii") === "xar!"
|
||||
magic.subarray(0, 4).equals(Buffer.from("xar!"))
|
||||
)
|
||||
return "pkg";
|
||||
if (lower.endsWith(".dmg")) {
|
||||
@@ -327,7 +330,7 @@ const detectArtifactFormat = async (
|
||||
const trailer = Buffer.alloc(4);
|
||||
const read = await handle.read(trailer, 0, trailer.length, size - 512);
|
||||
throwIfTargetResolutionCancelled(signal);
|
||||
if (read.bytesRead === 4 && trailer.toString("ascii") === "koly")
|
||||
if (read.bytesRead === 4 && trailer.equals(Buffer.from("koly")))
|
||||
return "dmg";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -504,14 +504,11 @@ const removeManagedSkills = async (
|
||||
environment: Readonly<NodeJS.ProcessEnv>,
|
||||
platform: NodeJS.Platform,
|
||||
): Promise<UninstallItem> => {
|
||||
// Every destination shares one summary item, so each result is labeled by
|
||||
// the directory it refers to.
|
||||
const results = await Promise.all(
|
||||
skillDestinations(home, undefined, environment, platform).map(
|
||||
({ client, path }) =>
|
||||
removeManagedSkill(
|
||||
path,
|
||||
client === "claude_code" ? "Claude Code skill" : "skill",
|
||||
fileSystem,
|
||||
),
|
||||
skillDestinations(home, undefined, environment, platform).map(({ path }) =>
|
||||
removeManagedSkill(path, path, fileSystem),
|
||||
),
|
||||
);
|
||||
const failed = results.find(({ status }) => status === "failed");
|
||||
|
||||
@@ -81,7 +81,9 @@ export class BinarySession
|
||||
| undefined;
|
||||
#transition: Promise<void> = Promise.resolve();
|
||||
#transitionGeneration = 0;
|
||||
#transitionPending = 0;
|
||||
readonly #calls = new Map<Promise<unknown>, number>();
|
||||
readonly #promptCompletionControllers = new Set<AbortController>();
|
||||
readonly #providerRouter: SessionProviderRouter;
|
||||
readonly #runtimeUnavailability = new Map<
|
||||
string,
|
||||
@@ -532,6 +534,38 @@ export class BinarySession
|
||||
return call.finally(() => this.#calls.delete(call));
|
||||
}
|
||||
|
||||
/** Run a prompt lookup only against an already connected provider child. */
|
||||
executeIfProviderReady(
|
||||
name: Parameters<AnalysisOperationPort["execute"]>[0],
|
||||
arguments_: Readonly<Record<string, JsonValue>>,
|
||||
options?: Pick<ExecutionOptions, "signal" | "selectorOrigin">,
|
||||
): Promise<Result<AnalysisExecution, AnalysisError> | undefined> {
|
||||
const active = this.#active;
|
||||
if (
|
||||
this.#transitionPending > 0 ||
|
||||
active === undefined ||
|
||||
active.client.executeIfReady === undefined
|
||||
)
|
||||
return Promise.resolve(undefined);
|
||||
|
||||
const controller = new AbortController();
|
||||
this.#promptCompletionControllers.add(controller);
|
||||
const signal =
|
||||
options?.signal === undefined
|
||||
? controller.signal
|
||||
: AbortSignal.any([controller.signal, options.signal]);
|
||||
const generation = this.#transitionGeneration;
|
||||
const call = active.client.executeIfReady(name, arguments_, {
|
||||
...options,
|
||||
signal,
|
||||
});
|
||||
this.#calls.set(call, generation);
|
||||
return call.finally(() => {
|
||||
this.#calls.delete(call);
|
||||
this.#promptCompletionControllers.delete(controller);
|
||||
});
|
||||
}
|
||||
|
||||
/** Admit one composed request until its result and session bookkeeping settle. */
|
||||
withAdmittedAnalysis<Value>(
|
||||
operationName: string,
|
||||
@@ -728,6 +762,9 @@ export class BinarySession
|
||||
#serialize<T>(
|
||||
operation: (admittedThrough: number) => Promise<T>,
|
||||
): Promise<T> {
|
||||
for (const controller of this.#promptCompletionControllers)
|
||||
controller.abort();
|
||||
this.#transitionPending += 1;
|
||||
// Later calls wait for this transition and must not be included in its drain.
|
||||
const admittedThrough = this.#transitionGeneration++;
|
||||
const result = this.#transition.then(
|
||||
@@ -738,6 +775,14 @@ export class BinarySession
|
||||
() => undefined,
|
||||
() => undefined,
|
||||
);
|
||||
void result.then(
|
||||
() => {
|
||||
this.#transitionPending -= 1;
|
||||
},
|
||||
() => {
|
||||
this.#transitionPending -= 1;
|
||||
},
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import type { EvidenceIntegrityError } from "../../domain/evidenceErrors.js";
|
||||
import type { WorkflowSnapshotRecordInput } from "./BinarySessionRecords.js";
|
||||
|
||||
import type {
|
||||
AnalysisExecution,
|
||||
AnalysisOperation,
|
||||
AnalysisOperationPort,
|
||||
ExecutionOptions,
|
||||
@@ -35,6 +36,12 @@ export interface SavedAnalysisSnapshot {
|
||||
/** Target lifecycle used by CLI and MCP without exposing a concrete provider. */
|
||||
export interface BinarySessionPort
|
||||
extends AnalysisOperationPort, InvestigationRecordPort {
|
||||
/** Execute only against a positively ready, already-created provider client. */
|
||||
executeIfProviderReady(
|
||||
operation: AnalysisOperation,
|
||||
parameters: Readonly<Record<string, JsonValue>>,
|
||||
options?: Pick<ExecutionOptions, "signal" | "selectorOrigin">,
|
||||
): Promise<Result<AnalysisExecution, AnalysisError> | undefined>;
|
||||
/** Hold the active target binding through a complete composed operation. */
|
||||
withAdmittedAnalysis<Value>(
|
||||
operationName: string,
|
||||
|
||||
@@ -94,6 +94,15 @@ export class CompositeProvider implements AnalysisProvider {
|
||||
return outcomes.find((outcome) => !outcome.ok) ?? ok(null);
|
||||
};
|
||||
return {
|
||||
executeIfReady: (operation, parameters, options) => {
|
||||
const provider = this.#providerByOperation.get(operation);
|
||||
const client =
|
||||
provider === undefined ? undefined : clients.get(provider);
|
||||
return (
|
||||
client?.executeIfReady?.(operation, parameters, options) ??
|
||||
Promise.resolve(undefined)
|
||||
);
|
||||
},
|
||||
execute: (operation, parameters, options) => {
|
||||
if (operation === "health")
|
||||
return Promise.resolve(
|
||||
|
||||
@@ -79,6 +79,14 @@ class LazyAnalysisClient implements AnalysisClient {
|
||||
#loading: Promise<AnalysisClient> | undefined;
|
||||
#closed = false;
|
||||
|
||||
executeIfReady: NonNullable<AnalysisClient["executeIfReady"]> = (
|
||||
operation,
|
||||
parameters,
|
||||
options,
|
||||
) =>
|
||||
this.#client?.executeIfReady?.(operation, parameters, options) ??
|
||||
Promise.resolve(undefined);
|
||||
|
||||
constructor(loadClient: () => Promise<AnalysisClient>, providerId: string) {
|
||||
this.#loadClient = loadClient;
|
||||
this.#providerId = providerId;
|
||||
|
||||
Reference in New Issue
Block a user