import { z } from "zod"; import type { ToolContract } from "./toolContracts.js"; import { artifactOutputSchemas } from "./toolOutputSchemas.js"; import { jsonValueSchema } from "../domain/jsonValue.js"; import { toolContractMetadata } from "./toolEffects.js"; import { requireOutputSchema } from "./toolOutputSchemaPrimitives.js"; const integrityInput = { fail: { integrity_policy: z.literal("fail").default("fail"), integrity_continue_approved: z.literal(false).default(false), }, continue: { integrity_policy: z.literal("record-and-continue"), integrity_continue_approved: z.literal(true), }, } as const; const artifactInventoryFacts = { native_mount_approved: z.boolean().default(false), } as const; /** Exact caller boundary for deterministic artifact inventory. */ export const artifactInventoryInputSchema = z.union([ z.object({ ...artifactInventoryFacts, ...integrityInput.fail }), z.object({ ...artifactInventoryFacts, ...integrityInput.continue }), ]); /** Extraction needs no selector: it materializes every regular child file. */ export const artifactExtractionInputSchema = z.strictObject({}); /** Provider input after the local permission boundary chooses its destination. */ export const artifactExtractionExecutionSchema = z.strictObject({ output_root: z.string().min(1), }); const exampleInputSchema = z.record(z.string(), jsonValueSchema); const examples: Readonly>>> = { inspect_artifact: {}, extract_artifact: {}, }; const artifact = < Name extends string, Schema extends z.ZodType>>, >( name: Name, description: string, inputSchema: Schema, ) => { const outputSchema = requireOutputSchema(artifactOutputSchemas, name); return { name, ...toolContractMetadata(name), description, kind: "artifact-provider", inputSchema, outputSchema, examples: [ { title: `Example ${name.replaceAll("_", " ")} request`, input: exampleInputSchema.parse(examples[name] ?? {}), }, ], } satisfies ToolContract; }; /** Artifact-graph inventory and safe extraction contracts. */ export const ARTIFACT_TOOL_CONTRACTS = [ artifact( "inspect_artifact", "Inspect an active archive or application package in one call. Returns the complete content-addressed artifact graph, source Evidence, observations, relationships, integrity contradictions, hypotheses, unexplored branches, limitations, and next probes inline. It does not extract files; use extract_artifact to materialize its regular contents.", artifactInventoryInputSchema, ), artifact( "extract_artifact", "Extract all regular files from the active archive or application package into a fresh temporary directory chosen by REA. The result includes its location. Rejects traversal and symlink escapes, never overwrites, enforces archive integrity checks, and verifies cleanup.", artifactExtractionInputSchema, ), ] as const satisfies readonly ToolContract[]; /** Provider operations; inventory remains an internal primitive of inspection. */ export const ARTIFACT_ANALYSIS_OPERATIONS = [ "inventory_artifact", ...ARTIFACT_TOOL_CONTRACTS.map(({ name }) => name), ] as const; /** Provider-level operations including the inventory primitive used internally. */ export type ArtifactAnalysisOperation = (typeof ARTIFACT_ANALYSIS_OPERATIONS)[number];