import type { StateMachineDef } from "./state-machine.js"; export type TaskState = "draft" | "planned" | "in-progress" | "done" | "archived"; export interface Task { list: string; id: string; qualifiedId: string; name: string; state: string; description: string; metadata: Record; sourcePath?: string; } export interface TaskCreate { id?: string; name: string; description?: string; metadata?: Record; } export interface TaskUpdate { name?: string; description?: string; metadata?: Record; state?: never; } export interface TaskFireOptions { metadataPatch?: Record; } export type TaskOrder = "priority" | "alphabetical" | "created"; export interface ListFilter { state?: string; includeArchived?: boolean; order?: TaskOrder; } export type MoveAnchor = { before: string; } | { after: string; } | { position: "top" | "bottom"; }; export interface Tasks { readonly name: string; readonly stateMachine: StateMachineDef; all(filter?: ListFilter): Promise; get(id: string): Promise; create(input: TaskCreate): Promise; update(id: string, patch: TaskUpdate): Promise; fire(id: string, event: string, opts?: TaskFireOptions): Promise; comment?(id: string, body: string): Promise; canFire(id: string, event: string): Promise; events(id: string): Promise; delete(id: string): Promise; move(id: string, anchor: MoveAnchor): Promise; reorder(ids: readonly string[]): Promise; } export interface TaskList { list(name: string): Tasks; lists(): Promise; allTasks(filter?: ListFilter): Promise; get(qualifiedId: string): Promise; moveBetweenLists(qualifiedId: string, targetList: string): Promise; } export interface TaskDefaults { metadata?: Record; } export interface TaskListFs { lstat(path: string): Promise<{ isSymbolicLink(): boolean; }>; mkdir(path: string, options?: { recursive?: boolean; }): Promise; readFile(path: string, encoding: BufferEncoding): Promise; readdir(path: string): Promise; rename(fromPath: string, toPath: string): Promise; stat(path: string): Promise<{ isDirectory(): boolean; isFile(): boolean; mtimeMs: number; }>; unlink(path: string): Promise; writeFile(path: string, data: string | NodeJS.ArrayBufferView, options?: BufferEncoding | { encoding?: BufferEncoding; flag?: string; }): Promise; } export type OpenTaskListOptions = OpenMarkdownDirOptions | OpenYamlFileOptions | OpenGhIssuesOptions; export type TaskListOptions = OpenTaskListOptions; export interface MoveTasksOptions { source: TaskListOptions; target: TaskListOptions; deleteSource?: boolean; limit?: number; rate?: number; dryRun?: boolean; stateMap?: Record; onProgress?: (event: MoveProgressEvent) => void; } export interface MoveResult { created: number; skipped: number; errors: Array<{ id: string; error: string; }>; } export type MoveProgressEvent = { type: "created"; id: string; source: Task; target: Task; targetList: string; targetState: string; } | { type: "skipped"; id: string; source: Task; targetList: string; targetState: string; reason: "dry-run"; } | { type: "error"; id: string; source: Task; error: string; }; export interface OpenMarkdownDirOptions { type: "markdown-dir"; path: string; defaults?: TaskDefaults; create?: boolean; singleList?: string; frontmatterMode?: "strict" | "passthrough"; fs?: TaskListFs; stateMachine?: StateMachineDef; } export interface OpenYamlFileOptions { type: "yaml-file"; path: string; defaults?: TaskDefaults; create?: boolean; fs?: TaskListFs; stateMachine?: StateMachineDef; } export interface OpenGhIssuesOptions { type: "gh-issues"; repo: string; project?: { owner: string; number: number; }; filter?: string; state?: { labelPrefix?: string; }; stateMachine?: StateMachineDef; defaults?: TaskDefaults; auth?: { token: string; }; fetch?: typeof fetch; } export interface BackendDeps { path: string; defaults: Required; singleList?: string; frontmatterMode: "strict" | "passthrough"; create: boolean; fs: TaskListFs; stateMachine?: StateMachineDef; } export type BackendFactory = (deps: BackendDeps) => Promise; export declare class TaskNotFoundError extends Error { constructor(message?: string); } export declare class TaskAlreadyExistsError extends Error { constructor(message?: string); } export declare class InvalidTransitionError extends Error { readonly task?: Task; readonly event?: string; readonly to?: string; readonly reason: string; constructor(messageOrOptions?: string | { task?: Task; event?: string; to?: string; reason: string; }); } export declare class MalformedTaskError extends Error { constructor(message?: string); } export declare class OrderMismatchError extends Error { readonly missing: readonly string[]; readonly extra: readonly string[]; constructor(options: { missing: readonly string[]; extra: readonly string[]; }); } export declare class AnchorNotFoundError extends Error { readonly anchor: string; constructor(anchor: string); }