@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
42 lines • 2.79 kB
TypeScript
/**
* The `checkpointed-file` durability class: the restore handler that makes a persistent file
* watch survive a restart. On create the monitor tool persists the registry's own identity
* tuple (dev/ino/size/mtimeMs/digest/present) as the manifest checkpoint; here that checkpoint
* is compared ONCE against the file as it is now, and any change that happened while the process
* was gone is reported as EXACTLY ONE line through the registry's normal event sink — so the
* notifier's coalescing and wake budget apply to it exactly as they do to a live watch event.
*
* `digest` is load-bearing: without it a same-size, same-mtime rewrite is invisible across a restart.
*/
import type { MonitorRegistry } from "./monitor-registry.ts";
import type { RestoreHandler } from "./restore.ts";
import type { TerminalManifestCheckpoint, TerminalManifestWriter } from "./terminal-manifest.ts";
/**
* What a detached change is reported as. `null` means the file is byte-identical to the checkpoint;
* `"gone"` means it existed at checkpoint time and does not now, which is not restorable.
*/
export type DetachedChange = "created" | "replaced" | "modified" | "gone" | null;
/** Only what the handler needs, so a caller can hand it a narrower registry/writer. */
export interface CheckpointedFileRestoreDeps {
readonly registry: Pick<MonitorRegistry, "registerFile" | "fileCheckpoint" | "emitFileLine" | "stopFile">;
/** Optional: the durable checkpoint is re-persisted through the writer when one is bound. */
readonly writer?: Pick<TerminalManifestWriter, "scheduleCheckpoint">;
/** Optional: re-bind the stable `mon_` id to its fresh runtime id so kill_bash keeps resolving it. */
readonly bindMonitorId?: (monitorId: string, runtimeId: string) => void;
readonly now?: () => number;
}
/** The live tuple `registry.fileCheckpoint` returns; identical in shape to the persisted checkpoint. */
type LiveCheckpoint = NonNullable<ReturnType<MonitorRegistry["fileCheckpoint"]>>;
/**
* The single comparison, run once per restore. `created` and `replaced` outrank `modified`:
* an absent→present transition or a new dev/ino is a stronger statement about the same file.
*/
export declare function classifyDetachedChange(saved: TerminalManifestCheckpoint, live: LiveCheckpoint): DetachedChange;
/**
* Build the `checkpointed-file` restore handler. It re-registers the watch under its original
* `mon_` id and approved parent (so the permission decision still holds), then reports at most
* one detached-change line. Returns `lost` when the path is gone or unreadable, `restored` otherwise.
*/
export declare function createCheckpointedFileRestoreHandler(deps: CheckpointedFileRestoreDeps): RestoreHandler;
export {};
//# sourceMappingURL=durable-file.d.ts.map