UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

27 lines (26 loc) • 2.75 kB
import type { AgentTool, ExecutionEnv } from "../../internal/harness-types.js"; import type { BeforeWriteHook, FileEditedHook, TrackFileEditHook } from "../../core/types.js"; import { type ReadFileState } from "./safety.js"; import type { ContainmentFace } from "./containment-face.js"; import { type WriteDenyMatcher } from "./read-deny.js"; import { type CwdRef } from "./fs-shared.js"; /** * The `beforeWrite` CONTENT hook, mounted here rather than in ToolPolicy because only this band sees * the FINAL text an Edit/NotebookEdit produces — the applied old→new full text is what actually lands * on disk. Called before EVERY `env.writeFile` in Write/Edit/NotebookEdit with the resolved * containment key and the exact text about to be written. Returning `{ ok:false }` makes the tool fail * with a structured error and NOTHING is written. The Runner wires this to the MemoryEngine's write * gate (`MemoryEngine.gateWrite`), where a non-memory path passes on one string prefix comparison. * Absent hook ⇒ byte-identical behavior. */ export type { BeforeWriteRequest, BeforeWriteResult, BeforeWriteHook, TrackEditRequest, TrackEditResult, TrackFileEditHook } from "../../core/types.js"; export declare function createEditFileTool(env: ExecutionEnv, state: ReadFileState, rootCanonical: string, cwdRef?: CwdRef, additionalRoots?: readonly string[], beforeWrite?: BeforeWriteHook, trackEdit?: TrackFileEditHook, onEdited?: FileEditedHook, writeFace?: () => ContainmentFace, writeDeny?: WriteDenyMatcher): AgentTool; export declare function createWriteFileTool(env: ExecutionEnv, state: ReadFileState, rootCanonical: string, cwdRef?: CwdRef, additionalRoots?: readonly string[], beforeWrite?: BeforeWriteHook, trackEdit?: TrackFileEditHook, onEdited?: FileEditedHook, writeFace?: () => ContainmentFace, writeDeny?: WriteDenyMatcher): AgentTool; /** * design v1.163 — NotebookEdit: replace/insert/delete a single cell in a .ipynb. CC-parity tool over the SAME hand-band * safety skeleton as Edit/Write (resolveKey containment → requireRead read-before-edit → checkStale content-hash * freshness → mutate → writeFile → state.set), with object ops swapped for ipynb-JSON cell mutation. Read serves * .ipynb as the cell projection but records read state (hash/totalLines) in the RAW notebook-text * coordinate — that raw-coordinate read record is what this tool's freshness check depends on. */ export declare function createNotebookEditTool(env: ExecutionEnv, state: ReadFileState, rootCanonical: string, cwdRef?: CwdRef, additionalRoots?: readonly string[], beforeWrite?: BeforeWriteHook, trackEdit?: TrackFileEditHook, onEdited?: FileEditedHook, writeFace?: () => ContainmentFace, writeDeny?: WriteDenyMatcher): AgentTool;