/** * Process-local attachment drafts and bounded filesystem reads. * * A draft deliberately retains a user-facing path, not bytes or an attachment * reference. The current session's filesystem resolves and reads it only when * the message is sent; the attachment store then validates and durably commits * the complete ordered batch before any content block enters the Agent inbox. * * ONE ordered ledger holds both kinds, because the order the reader staged in * is the order the message is built in. Two parallel lists would have to be * merged at send time, and every such merge is a place where "all the images, * then all the files" can quietly become the projection — which is not what * `/image a.png /attach trace.json /image b.png` asked for. * @module dshline/attachment-drafts */ import type { EncodedImageAttachment, ImageMediaType, SaveImageAttachment } from '@deepseek-ai/dsh-attachment'; import type { FileSystem } from '@deepseek-ai/dsh-fs'; /** A raster image staged for the current session's next ordinary prompt. */ export interface ImageDraft { /** Which durable content block this draft becomes. */ readonly kind: 'image'; /** Path in the session filesystem's vocabulary; never persisted by dshline. */ readonly path: string; /** Declared type inferred from the explicit raster suffix and verified by Harness. */ readonly mediaType: ImageMediaType; /** Basename-only display metadata handed to the attachment store. */ readonly name: string; } /** * A verbatim file staged for the current session's next ordinary prompt. * * There is no media type because there is no type: Harness stores these bytes * exactly and decides what they mean, so a suffix this frontend recognized * would be a policy the adopted attachment contract explicitly declines to own * here — files carry no admission limits precisely because storage is streamed * and content is consumed lazily. */ export interface FileDraft { /** Which durable content block this draft becomes. */ readonly kind: 'file'; /** Path in the session filesystem's vocabulary; never persisted by dshline. */ readonly path: string; /** Basename-only display metadata handed to the attachment store. */ readonly name: string; } /** One staged attachment, in the order it will appear in the next message. */ export type AttachmentDraft = ImageDraft | FileDraft; /** Result of trying to add one local path to the current image draft. */ export type StageImageResult = { readonly ok: true; readonly draft: ImageDraft; } | { readonly ok: false; readonly reason: 'empty' | 'unsupported-type' | 'deployment-type' | 'too-many' | 'duplicate'; }; /** * Result of trying to add one local path to the current file draft. * * Only `empty` and `duplicate` exist. The ordinary response to "you cannot * attach that" would be a size, an extension list, and a type check; none of * them is here, and adding one would mean this composer disagreeing with the * capability that actually owns the bytes. */ export type StageFileResult = { readonly ok: true; readonly draft: FileDraft; } | { readonly ok: false; readonly reason: 'empty' | 'duplicate'; }; /** Authoritative deployment facts usable before bytes are read. */ export interface ImageDraftPolicy { /** Maximum images in one message. */ readonly maxImages: number; /** Raster types this attachment provider currently admits. */ readonly mediaTypes: readonly ImageMediaType[]; } /** * Remove the optional mention sigil and one matching quote pair. * * The whole command remainder is one path, so spaces need no shell escaping. * Quotes are accepted only as outer presentation; backslashes remain path * characters because dshline must not invent a shell grammar over filesystem * names. * @param raw - text following `/image` or `/attach`. * @returns the path text, trimmed only at its outer boundary. */ export declare function stagedPath(raw: string): string; /** * The leaf name to hand the attachment store as a display name. * * `node:path.basename` is the wrong tool here. `ctx.fs` is an abstraction over * ONE execution world, not the host this process happens to run on: * `FsTarget.displayPath` is documented as possibly a local absolute path, a * workspace-relative path, or a remote URI. A provider on another platform can * hand back `C:\logs\server.log` while this process is POSIX, where `basename` * finds no `/` and returns the WHOLE STRING — a durable attachment name that is * a path, on a field that is persisted and then printed in every transcript. * * Both separators are therefore treated as separators regardless of host, which * is the one assumption a provider-neutral name can safely make: over-splitting a * name that genuinely contained a backslash costs a shorter label, while failing * to split one leaks the directory. A remote URI's authority and query are not * modelled — the leaf is the last segment, which is the part a reader needs. * * Derived from the STAGED path, not from a resolved target: `resolve` may * perform a round trip against a remote backend, and staging is a local * metadata operation. A path with no leaf at all — a bare root, or only * separators — has no name to give, and is given {@link UNNAMED_DRAFT} rather * than the root spelling, which is a path. * @param path - the staged path text, in the provider's own vocabulary. * @returns the leaf name, or {@link UNNAMED_DRAFT} when the path has none. */ export declare function displayName(path: string): string; /** * Infer the only image attachment kind Harness currently accepts. * * This is admission routing, not validation: the attachment store fully * decodes the bytes and rejects a false or mismatched suffix at send time. * @param path - path in the mounted filesystem's vocabulary. * @returns the declared raster media type, or undefined for a non-image suffix. */ export declare function imageMediaType(path: string): ImageMediaType | undefined; /** Session-scoped ordered collection of unsent attachment paths. */ export declare class AttachmentDrafts { #private; private readonly entries; /** Current drafts in staging order, which is the next message's block order. */ get items(): readonly AttachmentDraft[]; /** Only the image drafts, in staging order, for the `/image` list. */ get images(): readonly ImageDraft[]; /** Only the generic file drafts, in staging order, for the `/attach` list. */ get files(): readonly FileDraft[]; /** Number of attachments waiting for the next ordinary prompt. */ get size(): number; /** * Stage one image path without reading it or creating durable attachment objects. * @param raw - full command argument, optionally beginning with `@`. * @param policy - deployment count and media-type limits, when known. * @returns the accepted draft or a stable refusal reason. */ stageImage(raw: string, policy?: ImageDraftPolicy): StageImageResult; /** * Stage one verbatim file path. * * Deliberately reads nothing and checks nothing. The file may not exist yet, * may be a directory, may be unreadable, and may be replaced before the * message is sent; every one of those is a true statement the filesystem * answers at admission, when the reader has actually asked to send something. * Answering it here would be a second, staler authority than the one that has * to be right, and it would refuse paths the session's own filesystem can * reach and this terminal cannot name. * @param raw - full command argument, optionally beginning with `@`. * @returns the accepted draft or a stable refusal reason. */ stageFile(raw: string): StageFileResult; /** Remove every unsent draft, leaving no durable object behind. */ clear(): void; /** * Remove the image drafts only. * @returns how many image drafts were removed, for the acknowledgement. */ clearImages(): number; /** * Remove the generic file drafts only. * @returns how many file drafts were removed, for the acknowledgement. */ clearFiles(): number; /** * Remove one image draft by its one-based position in the `/image` list. * @param position - number shown by `/image`. * @returns the removed draft, or undefined when the position does not exist. */ removeImage(position: number): ImageDraft | undefined; /** * Remove one generic file draft by its one-based position in the `/attach` list. * @param position - number shown by `/attach`. * @returns the removed draft, or undefined when the position does not exist. */ removeFile(position: number): FileDraft | undefined; /** * Remove exactly the drafts one submission admitted, and nothing else. * * Identity-based rather than "clear whatever is staged now": a submission * owns only what was present when its admission began, and the ledger can * change while an unrelated command is in flight. Consuming by identity is * what keeps a draft the reader stages mid-submission out of an earlier * one's success. * * The pair `(kind, path)` is that identity: each kind refuses a duplicate * path within itself, so the pair is unique, while the SAME path may * legitimately be staged once as an image and once as a file. Keying on the * path alone would let one of them consume the other. * @param admitted - the snapshot one submission actually received. */ consume(admitted: readonly AttachmentDraft[]): void; } /** * Resolve and read draft paths through the current filesystem under a hard cap. * @param drafts - ordered process-local paths. * @param fs - current session's filesystem authority. * @param cwd - current session workspace for relative paths. * @param maxBytes - inclusive bound for each complete read. * @param maxTotalBytes - inclusive bound for the complete in-memory batch. * @param signal - optional cancellation shared by resolution and reads. * @returns raw, bounded inputs suitable for an authoritative Harness consumer. */ export declare function readImageDrafts(drafts: readonly ImageDraft[], fs: FileSystem, cwd: string, maxBytes: number, maxTotalBytes?: number, signal?: AbortSignal): Promise; /** * Serialize bounded draft inputs for the command registry's composer envelope. * * Base64 exists only at this immediate call boundary; dshline never stores or * logs it. The registry decodes, validates, and durably admits the batch before * an attachment-authorized command handler runs. * @param inputs - bounded bytes read from the mounted filesystem. * @returns ordered transient command image envelopes. */ export declare function encodeCommandImages(inputs: readonly SaveImageAttachment[]): readonly EncodedImageAttachment[]; //# sourceMappingURL=attachment-drafts.d.ts.map