@stll/folio-cli 0.5.3 → 0.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,13 +4,13 @@ import { Result } from "better-result";
4
4
  import { FolioAgentBridge } from "@stll/folio-agents/bridge";
5
5
  import { FolioAgentToolOptions } from "@stll/folio-agents/suggest-changes-options";
6
6
  //#region src/batch-operations.d.ts
7
- declare const BATCH_OPERATION_TYPES: readonly ["replaceAll", "addComment"];
7
+ export declare const BATCH_OPERATION_TYPES: readonly ["replaceAll", "addComment"];
8
8
  /**
9
9
  * `suggest_changes`' arguments with the batch operations added to the
10
10
  * operation schema: their types in the `type` enum and their extra fields.
11
11
  */
12
- declare const withBatchOperations: (schema: JsonObjectSchema) => JsonObjectSchema;
13
- type ExpandedBatch = {
12
+ export declare const withBatchOperations: (schema: JsonObjectSchema) => JsonObjectSchema;
13
+ export type ExpandedBatch = {
14
14
  operations: unknown[];
15
15
  /** Options the expanded batch needs from `suggest_changes`. */
16
16
  options: FolioAgentToolOptions;
@@ -24,6 +24,5 @@ type ExpandedBatch = {
24
24
  * Expand the batch operations of a `suggest_changes` call against the
25
25
  * document the bridge holds. Contract operations pass through unchanged.
26
26
  */
27
- declare const expandBatchOperations: (operations: unknown, bridge: FolioAgentBridge) => Result<ExpandedBatch, FolioCliError>;
28
- //#endregion
29
- export { BATCH_OPERATION_TYPES, ExpandedBatch, expandBatchOperations, withBatchOperations };
27
+ export declare const expandBatchOperations: (operations: unknown, bridge: FolioAgentBridge) => Result<ExpandedBatch, FolioCliError>;
28
+ //#endregion
package/dist/cli.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Readable, Writable } from "node:stream";
2
2
  //#region src/cli.d.ts
3
3
  /** The process surface the command line reads from and writes to. */
4
- type FolioCliIo = {
4
+ export type FolioCliIo = {
5
5
  stdout: (text: string) => void;
6
6
  stderr: (text: string) => void;
7
7
  readStdin: () => Promise<string>;
@@ -20,6 +20,5 @@ type FolioCliIo = {
20
20
  untilInterrupted?: () => Promise<void>;
21
21
  };
22
22
  /** Run `folio` with the given arguments (without the executable); resolves to the exit code. */
23
- declare const runFolioCli: (argv: readonly string[], io: FolioCliIo) => Promise<number>;
24
- //#endregion
25
- export { FolioCliIo, runFolioCli };
23
+ export declare const runFolioCli: (argv: readonly string[], io: FolioCliIo) => Promise<number>;
24
+ //#endregion
package/dist/cli.js CHANGED
@@ -269,8 +269,9 @@ const requestedFormat = (argv, io) => {
269
269
  return isOutputFormat(value) ? value : defaultFormat(io);
270
270
  };
271
271
  const emit = ({ io, format, tool, result }) => {
272
+ const envelope = result.isOk() ? successEnvelope(result.value) : failureEnvelope(result.error);
272
273
  const rendered = renderEnvelope({
273
- envelope: result.isOk() ? successEnvelope(result.value) : failureEnvelope(result.error),
274
+ envelope,
274
275
  format,
275
276
  tool
276
277
  });
@@ -4,10 +4,10 @@ import { Result } from "better-result";
4
4
  import { FolioDocxReviewer } from "@stll/folio-core/server";
5
5
  //#region src/document.d.ts
6
6
  /** Largest `.docx` the CLI opens; larger inputs are refused before reading. */
7
- declare const MAX_DOCUMENT_BYTES: number;
8
- declare const isFileVersion: (value: unknown) => value is string;
7
+ export declare const MAX_DOCUMENT_BYTES: number;
8
+ export declare const isFileVersion: (value: unknown) => value is string;
9
9
  /** The bytes of one input file and the version they hash to. */
10
- type LoadedFile = {
10
+ export type LoadedFile = {
11
11
  /** Real path (symlinks resolved) the bytes were read from. */
12
12
  path: string;
13
13
  bytes: Uint8Array<ArrayBuffer>;
@@ -22,7 +22,7 @@ type LoadedFile = {
22
22
  * that takes a document reads it here, so none can treat an archive without
23
23
  * a main document part as an empty document.
24
24
  */
25
- declare const readDocumentFile: (inputPath: string) => Promise<Result<LoadedFile, FolioCliError>>;
25
+ export declare const readDocumentFile: (inputPath: string) => Promise<Result<LoadedFile, FolioCliError>>;
26
26
  /**
27
27
  * Where a block id comes from. `package` ids are the paragraph's own
28
28
  * `w14:paraId` in the file; `synthetic` ids were minted for a paragraph the
@@ -30,9 +30,9 @@ declare const readDocumentFile: (inputPath: string) => Promise<Result<LoadedFile
30
30
  * first change written to such a file stores them, so from then on they are
31
31
  * the package's own.
32
32
  */
33
- type FolioBlockIdSource = "package" | "synthetic";
33
+ export type FolioBlockIdSource = "package" | "synthetic";
34
34
  /** A reviewer over one file and which of its block ids the file itself carries. */
35
- type OpenedDocument = {
35
+ export type OpenedDocument = {
36
36
  reviewer: FolioDocxReviewer;
37
37
  /** Ids minted for paragraphs without one; `null` when none could be minted up front. */
38
38
  mintedIds: ReadonlySet<string> | null;
@@ -41,8 +41,8 @@ type OpenedDocument = {
41
41
  * Parse a loaded file into a headless reviewer. `author` is required for a
42
42
  * reviewer that will author changes; reads pass none and never write.
43
43
  */
44
- declare const openReviewer: (file: LoadedFile, author?: string) => Promise<Result<OpenedDocument, FolioCliError>>;
44
+ export declare const openReviewer: (file: LoadedFile, author?: string) => Promise<Result<OpenedDocument, FolioCliError>>;
45
45
  /** Refuse when the caller's expected version is not the file's current one. */
46
- declare const checkExpectedVersion: (file: LoadedFile, expected: string | undefined) => Result<void, FolioCliError>;
46
+ export declare const checkExpectedVersion: (file: LoadedFile, expected: string | undefined) => Result<void, FolioCliError>;
47
47
  //#endregion
48
- export { type FileIdentity, FolioBlockIdSource, LoadedFile, MAX_DOCUMENT_BYTES, NO_FOLLOW, OpenedDocument, checkExpectedVersion, errnoCode, fileVersionOf, isFileVersion, openReviewer, readDocumentFile, sameFile };
48
+ export { type FileIdentity, NO_FOLLOW, errnoCode, fileVersionOf, sameFile };
package/dist/document.js CHANGED
@@ -8,7 +8,7 @@ import path from "node:path";
8
8
  import { FolioDocxReviewer, ensureParaIds } from "@stll/folio-core/server";
9
9
  //#region src/document.ts
10
10
  /** Largest `.docx` the CLI opens; larger inputs are refused before reading. */
11
- const MAX_DOCUMENT_BYTES = 64 * 1024 * 1024;
11
+ const MAX_DOCUMENT_BYTES = 67108864;
12
12
  const FILE_VERSION_PATTERN = /^[0-9a-f]{64}$/u;
13
13
  const isFileVersion = (value) => typeof value === "string" && FILE_VERSION_PATTERN.test(value);
14
14
  const describeError = (error) => error instanceof Error ? error.message : String(error);
@@ -3,15 +3,15 @@ import { FolioCliError } from "./errors.js";
3
3
  import { Result } from "better-result";
4
4
  //#region src/editor-lease.d.ts
5
5
  /** How long an editor's lease lasts without renewal. */
6
- declare const EDITOR_LEASE_MS: number;
6
+ export declare const EDITOR_LEASE_MS: number;
7
7
  /** How often an editor renews its lease while it holds it. */
8
- declare const EDITOR_RENEW_MS: number;
8
+ export declare const EDITOR_RENEW_MS: number;
9
9
  /** How long a writer waits for an editor to save and release by default. */
10
- declare const DEFAULT_FLUSH_WAIT_MS: number;
10
+ export declare const DEFAULT_FLUSH_WAIT_MS: number;
11
11
  /** How often a writer retries the lease, and an editor re-checks for requests. */
12
- declare const FLUSH_POLL_MS = 100;
12
+ export declare const FLUSH_POLL_MS = 100;
13
13
  /** A writer's request that the editor holding `leaseToken` save and release. */
14
- type FlushRequest = {
14
+ export type FlushRequest = {
15
15
  id: string;
16
16
  /** The token of the lease the writer found; an editor answers only its own. */
17
17
  leaseToken: string;
@@ -25,17 +25,17 @@ type FlushRequest = {
25
25
  deadline: string;
26
26
  };
27
27
  /** Request metadata safe to include in a refused editor lease response. */
28
- type PublicFlushRequest = Omit<FlushRequest, "leaseToken"> & {
28
+ export type PublicFlushRequest = Omit<FlushRequest, "leaseToken"> & {
29
29
  leaseToken?: never;
30
30
  };
31
- declare const flushRequestPathFor: (documentPath: string, id: string) => string;
31
+ export declare const flushRequestPathFor: (documentPath: string, id: string) => string;
32
32
  /**
33
33
  * The flush requests beside `documentPath` whose writer is still waiting.
34
34
  * Requests past their deadline (a writer that crashed) are removed.
35
35
  */
36
- declare const pendingFlushRequests: (documentPath: string, now?: Date) => Promise<FlushRequest[]>;
36
+ export declare const pendingFlushRequests: (documentPath: string, now?: Date) => Promise<FlushRequest[]>;
37
37
  /** Whether a writer waited for an editor, and what came of it. */
38
- type FlushOutcome =
38
+ export type FlushOutcome =
39
39
  /** The lease was free, stale, or held by a holder that does not flush; no one was asked. */
40
40
  {
41
41
  type: "notAsked";
@@ -51,7 +51,7 @@ type FlushOutcome =
51
51
  type: "timedOut";
52
52
  holder: PublicLockHolder;
53
53
  };
54
- type LeaseForWrite = {
54
+ export type LeaseForWrite = {
55
55
  lease: AcquiredLease;
56
56
  flush: FlushOutcome;
57
57
  };
@@ -69,7 +69,7 @@ type AcquireLeaseForWriteOptions = {
69
69
  * Take the lease for a write. An editor holding it with unsaved edits is
70
70
  * asked to save and release first; see the module comment for the rules.
71
71
  */
72
- declare const acquireLeaseForWrite: ({ documentPath, txId, force, owner, flushWaitMs, pollMs }: AcquireLeaseForWriteOptions) => Promise<Result<LeaseForWrite, FolioCliError>>;
72
+ export declare const acquireLeaseForWrite: ({ documentPath, txId, force, owner, flushWaitMs, pollMs }: AcquireLeaseForWriteOptions) => Promise<Result<LeaseForWrite, FolioCliError>>;
73
73
  type AcquireEditorLeaseOptions = {
74
74
  documentPath: string;
75
75
  /** The editor's lease owner, such as `folio-vscode`. */
@@ -84,8 +84,8 @@ type AcquireEditorLeaseOptions = {
84
84
  * renewable, and answering flush requests. Refused (`locked`) while another
85
85
  * holder has it or a writer's flush request is pending.
86
86
  */
87
- declare const acquireEditorLease: ({ documentPath, owner, txId, leaseMs, now }: AcquireEditorLeaseOptions) => Promise<Result<AcquiredLease, FolioCliError>>;
88
- type LeaseKeeper = {
87
+ export declare const acquireEditorLease: ({ documentPath, owner, txId, leaseMs, now }: AcquireEditorLeaseOptions) => Promise<Result<AcquiredLease, FolioCliError>>;
88
+ export type LeaseKeeper = {
89
89
  stop: () => void;
90
90
  };
91
91
  /**
@@ -93,11 +93,11 @@ type LeaseKeeper = {
93
93
  * (the lease was taken over or expired), renewing stops and `onLost` runs:
94
94
  * the editor must not save under it again.
95
95
  */
96
- declare const keepEditorLeaseAlive: (lease: AcquiredLease, { intervalMs, onLost }: {
96
+ export declare const keepEditorLeaseAlive: (lease: AcquiredLease, { intervalMs, onLost }: {
97
97
  intervalMs?: number;
98
98
  onLost: (error: FolioCliError) => void;
99
99
  }) => LeaseKeeper;
100
- type FlushWatcher = {
100
+ export type FlushWatcher = {
101
101
  close: () => void;
102
102
  };
103
103
  type WatchFlushRequestsOptions = {
@@ -113,6 +113,6 @@ type WatchFlushRequestsOptions = {
113
113
  * watch for promptness plus a poll every `pollMs`, since watch events can
114
114
  * be dropped or unsupported (network drives).
115
115
  */
116
- declare const watchFlushRequests: ({ documentPath, token, onRequest, pollMs }: WatchFlushRequestsOptions) => FlushWatcher;
116
+ export declare const watchFlushRequests: ({ documentPath, token, onRequest, pollMs }: WatchFlushRequestsOptions) => FlushWatcher;
117
117
  //#endregion
118
- export { DEFAULT_FLUSH_WAIT_MS, EDITOR_LEASE_MS, EDITOR_RENEW_MS, FLUSH_POLL_MS, FlushOutcome, FlushRequest, FlushWatcher, LeaseForWrite, LeaseKeeper, PublicFlushRequest, acquireEditorLease, acquireLeaseForWrite, flushRequestPathFor, keepEditorLeaseAlive, pendingFlushRequests, watchFlushRequests };
118
+ export {};
@@ -56,11 +56,11 @@ import { setTimeout } from "node:timers/promises";
56
56
  * a save names the version it was based on and refuses a stale one.
57
57
  */
58
58
  /** How long an editor's lease lasts without renewal. */
59
- const EDITOR_LEASE_MS = 30 * 1e3;
59
+ const EDITOR_LEASE_MS = 3e4;
60
60
  /** How often an editor renews its lease while it holds it. */
61
- const EDITOR_RENEW_MS = 10 * 1e3;
61
+ const EDITOR_RENEW_MS = 1e4;
62
62
  /** How long a writer waits for an editor to save and release by default. */
63
- const DEFAULT_FLUSH_WAIT_MS = 5 * 1e3;
63
+ const DEFAULT_FLUSH_WAIT_MS = 5e3;
64
64
  /** How often a writer retries the lease, and an editor re-checks for requests. */
65
65
  const FLUSH_POLL_MS = 100;
66
66
  const publicFlushRequest = ({ id, owner, pid, host, txId, requestedAt, deadline }) => ({
package/dist/errors.d.ts CHANGED
@@ -6,7 +6,7 @@ import { PublicFlushRequest } from "./editor-lease.js";
6
6
  * a script driving both branches on one set of codes; folio uses the subset a
7
7
  * local file tool can produce.
8
8
  */
9
- declare const EXIT_CODES: {
9
+ export declare const EXIT_CODES: {
10
10
  readonly ok: 0;
11
11
  readonly unexpected: 1;
12
12
  readonly validation: 2;
@@ -14,14 +14,14 @@ declare const EXIT_CODES: {
14
14
  readonly permissionDenied: 8;
15
15
  readonly conflict: 10;
16
16
  };
17
- type ExitCode = (typeof EXIT_CODES)[keyof typeof EXIT_CODES];
17
+ export type ExitCode = (typeof EXIT_CODES)[keyof typeof EXIT_CODES];
18
18
  /** Every exit code with its meaning, ordered numerically, for `--help`. */
19
- declare const exitCodeEntries: () => readonly {
19
+ export declare const exitCodeEntries: () => readonly {
20
20
  code: number;
21
21
  meaning: string;
22
22
  }[];
23
23
  /** Machine codes carried in `error.code` of a failure envelope. */
24
- declare const FOLIO_CLI_ERROR_CODES: {
24
+ export declare const FOLIO_CLI_ERROR_CODES: {
25
25
  readonly usage: "usage_error";
26
26
  readonly invalidInput: "invalid_input";
27
27
  readonly invalidDocument: "invalid_document";
@@ -43,10 +43,10 @@ declare const FOLIO_CLI_ERROR_CODES: {
43
43
  readonly rendererUnavailable: "renderer_unavailable";
44
44
  readonly internal: "internal_error";
45
45
  };
46
- type FolioCliErrorCode = (typeof FOLIO_CLI_ERROR_CODES)[keyof typeof FOLIO_CLI_ERROR_CODES];
47
- declare const exitCodeForError: (code: FolioCliErrorCode) => ExitCode;
46
+ export type FolioCliErrorCode = (typeof FOLIO_CLI_ERROR_CODES)[keyof typeof FOLIO_CLI_ERROR_CODES];
47
+ export declare const exitCodeForError: (code: FolioCliErrorCode) => ExitCode;
48
48
  /** Public error context. Lease-bearing fields cannot accept internal records. */
49
- type PublicErrorDetails = {
49
+ export type PublicErrorDetails = {
50
50
  readonly [key: string]: unknown;
51
51
  readonly holder?: PublicLockHolder;
52
52
  readonly pending?: readonly PublicFlushRequest[];
@@ -59,7 +59,7 @@ declare const FolioCliError_base: import("better-result").TaggedErrorClass<"Foli
59
59
  * step (re-read, pass a flag); `details` carries structured context such as
60
60
  * the skipped operations of a refused batch.
61
61
  */
62
- declare class FolioCliError extends FolioCliError_base<{
62
+ export declare class FolioCliError extends FolioCliError_base<{
63
63
  code: FolioCliErrorCode;
64
64
  message: string;
65
65
  hint?: string;
@@ -72,6 +72,6 @@ type CliErrorOptions = {
72
72
  details?: PublicErrorDetails;
73
73
  };
74
74
  /** Build a {@link FolioCliError} without spelling absent optional fields. */
75
- declare const cliError: ({ code, message, hint, details }: CliErrorOptions) => FolioCliError;
75
+ export declare const cliError: ({ code, message, hint, details }: CliErrorOptions) => FolioCliError;
76
76
  //#endregion
77
- export { EXIT_CODES, ExitCode, FOLIO_CLI_ERROR_CODES, FolioCliError, FolioCliErrorCode, PublicErrorDetails, cliError, exitCodeEntries, exitCodeForError };
77
+ export {};
@@ -4,14 +4,14 @@ import { FolioBlockIdSource, OpenedDocument } from "./document.js";
4
4
  import { Result } from "better-result";
5
5
  //#region src/execute-read.d.ts
6
6
  /** One call against one file: the envelope plus the tool's own arguments. */
7
- type FileToolCall = {
7
+ export type FileToolCall = {
8
8
  path: string;
9
9
  /** When present, the call is refused unless the file still has this version. */
10
10
  fileVersion?: string | undefined;
11
11
  args: Readonly<Record<string, unknown>>;
12
12
  };
13
13
  /** Per-surface limits on what one read returns. */
14
- type FolioReadBounds = {
14
+ export type FolioReadBounds = {
15
15
  /** Page size when `read_document` passes none; `null` returns every block. */
16
16
  defaultMaxBlocks: number | null;
17
17
  /** Most `find_text` matches returned; the rest are counted, not listed. */
@@ -19,29 +19,29 @@ type FolioReadBounds = {
19
19
  /** Largest serialized result; `null` for no limit. */
20
20
  maxResponseBytes: number | null;
21
21
  };
22
- declare const CLI_READ_BOUNDS: FolioReadBounds;
22
+ export declare const CLI_READ_BOUNDS: FolioReadBounds;
23
23
  /** The data every file read returns: which file, at which version, and the result. */
24
- type FileReadData = {
24
+ export type FileReadData = {
25
25
  path: string;
26
26
  fileVersion: string;
27
27
  result: unknown;
28
28
  };
29
29
  type BlockIdSources = ReadonlyMap<string, FolioBlockIdSource>;
30
- declare const blockIdSources: ({ reviewer, mintedIds }: OpenedDocument) => BlockIdSources;
30
+ export declare const blockIdSources: ({ reviewer, mintedIds }: OpenedDocument) => BlockIdSources;
31
31
  /** Where a block inside a table sits: zero-based table, row, and cell indexes. */
32
- type FolioTableCell = {
32
+ export type FolioTableCell = {
33
33
  table: number;
34
34
  row: number;
35
35
  cell: number;
36
36
  };
37
37
  type TableCells = ReadonlyMap<string, FolioTableCell>;
38
38
  /** The table cell of every block that sits in one. */
39
- declare const tableCells: ({ reviewer }: OpenedDocument) => TableCells;
39
+ export declare const tableCells: ({ reviewer }: OpenedDocument) => TableCells;
40
40
  type ReadCursor = {
41
41
  fileVersion: string;
42
42
  afterBlockId: string;
43
43
  };
44
- declare const encodeReadCursor: ({ fileVersion, afterBlockId }: ReadCursor) => string;
44
+ export declare const encodeReadCursor: ({ fileVersion, afterBlockId }: ReadCursor) => string;
45
45
  type ReadDocumentPage = {
46
46
  blocks: unknown[];
47
47
  totalBlocks: number;
@@ -63,8 +63,8 @@ type PageReadDocumentOptions = {
63
63
  * the last block of the previous page and the version it was read at, so a
64
64
  * page from one version never continues on another.
65
65
  */
66
- declare const pageReadDocument: ({ blocks, sources, cells, fileVersion, args, bounds, pageByteBudget }: PageReadDocumentOptions) => Result<ReadDocumentPage, FolioCliError>;
66
+ export declare const pageReadDocument: ({ blocks, sources, cells, fileVersion, args, bounds, pageByteBudget }: PageReadDocumentOptions) => Result<ReadDocumentPage, FolioCliError>;
67
67
  /** Run one read tool, or a compare without a destination. Never writes. */
68
- declare const executeReadTool: (tool: FolioFileToolSpec, call: FileToolCall, bounds: FolioReadBounds) => Promise<Result<FileReadData, FolioCliError>>;
68
+ export declare const executeReadTool: (tool: FolioFileToolSpec, call: FileToolCall, bounds: FolioReadBounds) => Promise<Result<FileReadData, FolioCliError>>;
69
69
  //#endregion
70
- export { CLI_READ_BOUNDS, FileReadData, FileToolCall, type FolioBlockIdSource, FolioReadBounds, FolioTableCell, blockIdSources, encodeReadCursor, executeReadTool, pageReadDocument, tableCells };
70
+ export type { FolioBlockIdSource };
@@ -8,7 +8,7 @@ import { Result } from "better-result";
8
8
  import { FolioAIEditApplyMode } from "@stll/folio-core/server";
9
9
  //#region src/execute-write.d.ts
10
10
  /** Everything about a write that is not the tool's own arguments. */
11
- type WriteOptions = {
11
+ export type WriteOptions = {
12
12
  destination: WriteDestination;
13
13
  /** Already resolved: a write never proceeds without one. */
14
14
  author: string;
@@ -33,17 +33,17 @@ type WriteOptions = {
33
33
  flushWaitMs?: number;
34
34
  };
35
35
  /** How a transaction's bytes were produced. */
36
- type SaveStrategy = "selective" | "full-repack" | "redline";
37
- declare const TX_ID_PATTERN: RegExp;
36
+ export type SaveStrategy = "selective" | "full-repack" | "redline";
37
+ export declare const TX_ID_PATTERN: RegExp;
38
38
  /** JSON with object keys sorted at every depth, for a stable request hash. */
39
- declare const canonicalJson: (value: unknown) => string;
39
+ export declare const canonicalJson: (value: unknown) => string;
40
40
  type ResolvedTarget = {
41
41
  sourcePath: string;
42
42
  sourceIdentity: FileIdentity;
43
43
  destinationPath: string;
44
44
  };
45
45
  /** The `tool` an editor's whole-package save journals (`save.ts`). */
46
- declare const EDITOR_SAVE_TOOL = "editor_save";
46
+ export declare const EDITOR_SAVE_TOOL = "editor_save";
47
47
  type ResolveTargetOptions = {
48
48
  sourcePath: string;
49
49
  destination: WriteDestination;
@@ -57,8 +57,8 @@ type ResolveTargetOptions = {
57
57
  * that is the input under another name (a symlink, a hard link, a
58
58
  * case-insensitive alias): files are compared by device and inode.
59
59
  */
60
- declare const resolveTarget: ({ sourcePath, destination, redline }: ResolveTargetOptions) => Promise<Result<ResolvedTarget, FolioCliError>>;
60
+ export declare const resolveTarget: ({ sourcePath, destination, redline }: ResolveTargetOptions) => Promise<Result<ResolvedTarget, FolioCliError>>;
61
61
  /** Run one write tool as a transaction and return its receipt. */
62
- declare const executeWriteTool: (tool: FolioFileToolSpec, call: FileToolCall, options: WriteOptions) => Promise<Result<Readonly<Record<string, unknown>>, FolioCliError>>;
62
+ export declare const executeWriteTool: (tool: FolioFileToolSpec, call: FileToolCall, options: WriteOptions) => Promise<Result<Readonly<Record<string, unknown>>, FolioCliError>>;
63
63
  //#endregion
64
- export { EDITOR_SAVE_TOOL, SaveStrategy, TX_ID_PATTERN, type WriteDestination, WriteOptions, canonicalJson, executeWriteTool, resolveTarget };
64
+ export type { WriteDestination };
@@ -5,19 +5,18 @@
5
5
  * editor host bundles) does not pull in the parser.
6
6
  */
7
7
  /** A file's version: the lowercase hex SHA-256 of its bytes. */
8
- declare const fileVersionOf: (bytes: Uint8Array) => string;
8
+ export declare const fileVersionOf: (bytes: Uint8Array) => string;
9
9
  /** Which file a path named when it was read: device and inode. */
10
- type FileIdentity = {
10
+ export type FileIdentity = {
11
11
  dev: number;
12
12
  ino: number;
13
13
  };
14
- declare const sameFile: (left: FileIdentity, right: FileIdentity) => boolean;
14
+ export declare const sameFile: (left: FileIdentity, right: FileIdentity) => boolean;
15
15
  /**
16
16
  * `O_NOFOLLOW` where the platform has it: opening a path whose last
17
17
  * component is a symlink fails instead of following it.
18
18
  */
19
- declare const NO_FOLLOW: number;
19
+ export declare const NO_FOLLOW: number;
20
20
  /** The `code` of a Node.js file-system error, when there is one. */
21
- declare const errnoCode: (error: unknown) => string | undefined;
22
- //#endregion
23
- export { FileIdentity, NO_FOLLOW, errnoCode, fileVersionOf, sameFile };
21
+ export declare const errnoCode: (error: unknown) => string | undefined;
22
+ //#endregion
package/dist/flags.d.ts CHANGED
@@ -3,9 +3,9 @@ import { JsonObjectSchema } from "./registry.js";
3
3
  import { Result } from "better-result";
4
4
  //#region src/flags.d.ts
5
5
  /** Largest `--input` document accepted. */
6
- declare const MAX_INPUT_BYTES: number;
7
- type FlagValueType = "boolean" | "integer" | "number" | "string" | "strings" | "json";
8
- type GeneratedFlag = {
6
+ export declare const MAX_INPUT_BYTES: number;
7
+ export type FlagValueType = "boolean" | "integer" | "number" | "string" | "strings" | "json";
8
+ export type GeneratedFlag = {
9
9
  /** The schema property the flag sets. */
10
10
  property: string;
11
11
  /** `--flag` spelling, without the dashes. */
@@ -13,18 +13,18 @@ type GeneratedFlag = {
13
13
  valueType: FlagValueType;
14
14
  description: string;
15
15
  };
16
- declare const kebabCase: (name: string) => string;
16
+ export declare const kebabCase: (name: string) => string;
17
17
  /**
18
18
  * One flag per top-level schema property, in declaration order. `flagNames`
19
19
  * renames a property's flag (`{ ids: "id" }` for `--id`).
20
20
  */
21
- declare const flagsForSchema: (schema: JsonObjectSchema, flagNames?: Readonly<Record<string, string>>) => GeneratedFlag[];
21
+ export declare const flagsForSchema: (schema: JsonObjectSchema, flagNames?: Readonly<Record<string, string>>) => GeneratedFlag[];
22
22
  type CoerceFlagOptions = {
23
23
  flag: GeneratedFlag;
24
24
  raw: string | boolean | readonly string[];
25
25
  };
26
26
  /** Convert one parsed flag value to the type its schema property declares. */
27
- declare const coerceFlag: ({ flag, raw }: CoerceFlagOptions) => Result<unknown, FolioCliError>;
27
+ export declare const coerceFlag: ({ flag, raw }: CoerceFlagOptions) => Result<unknown, FolioCliError>;
28
28
  type ReadInputOptions = {
29
29
  source: string;
30
30
  readStdin: () => Promise<string>;
@@ -33,6 +33,6 @@ type ReadInputOptions = {
33
33
  * Read `--input`: `@path` reads a file, `-` reads stdin, anything else is
34
34
  * inline JSON. The result must be a JSON object or array.
35
35
  */
36
- declare const readInputSource: ({ source, readStdin }: ReadInputOptions) => Promise<Result<Record<string, unknown> | unknown[], FolioCliError>>;
36
+ export declare const readInputSource: ({ source, readStdin }: ReadInputOptions) => Promise<Result<Record<string, unknown> | unknown[], FolioCliError>>;
37
37
  //#endregion
38
- export { FlagValueType, GeneratedFlag, MAX_INPUT_BYTES, coerceFlag, flagsForSchema, kebabCase, readInputSource };
38
+ export {};
package/dist/flags.js CHANGED
@@ -12,7 +12,7 @@ import { readFile } from "node:fs/promises";
12
12
  * flags given alongside it override its fields.
13
13
  */
14
14
  /** Largest `--input` document accepted. */
15
- const MAX_INPUT_BYTES = 16 * 1024 * 1024;
15
+ const MAX_INPUT_BYTES = 16777216;
16
16
  const kebabCase = (name) => name.replace(/[A-Z]/gu, (letter) => `-${letter.toLowerCase()}`);
17
17
  const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
18
18
  const valueTypeOf = (schema) => {
package/dist/journal.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { FolioCliError } from "./errors.js";
2
2
  import { Result } from "better-result";
3
3
  //#region src/journal.d.ts
4
- type JournalCommit = {
4
+ export type JournalCommit = {
5
5
  type: "commit";
6
6
  txId: string;
7
7
  /** Hash of the request, so a retry with the same txId but other arguments is refused. */
@@ -24,9 +24,9 @@ type JournalCommit = {
24
24
  /** What the command returned, replayed verbatim for a retry with the same txId. */
25
25
  receipt: Readonly<Record<string, unknown>>;
26
26
  };
27
- declare const RECOVERY_DISCARD_REASONS: readonly ["notJournaled", "otherDocument", "notRegularFile", "stageChanged", "invalidPackage", "destinationMoved", "leaseLost", "renameRefused"];
28
- type RecoveryDiscardReason = (typeof RECOVERY_DISCARD_REASONS)[number];
29
- type JournalRecovery = {
27
+ export declare const RECOVERY_DISCARD_REASONS: readonly ["notJournaled", "otherDocument", "notRegularFile", "stageChanged", "invalidPackage", "destinationMoved", "leaseLost", "renameRefused"];
28
+ export type RecoveryDiscardReason = (typeof RECOVERY_DISCARD_REASONS)[number];
29
+ export type JournalRecovery = {
30
30
  type: "recovery";
31
31
  txId: string;
32
32
  path: string;
@@ -37,9 +37,9 @@ type JournalRecovery = {
37
37
  action: "discarded";
38
38
  reason: RecoveryDiscardReason;
39
39
  });
40
- type JournalEntry = JournalCommit | JournalRecovery;
40
+ export type JournalEntry = JournalCommit | JournalRecovery;
41
41
  /** The fields of a commit line recovery and replay read back. */
42
- type CommittedTransaction = {
42
+ export type CommittedTransaction = {
43
43
  txId: string;
44
44
  path: string;
45
45
  requestHash: string;
@@ -47,17 +47,17 @@ type CommittedTransaction = {
47
47
  destinationVersionBefore: string | null;
48
48
  receipt: Readonly<Record<string, unknown>>;
49
49
  };
50
- declare const journalPathFor: (documentPath: string, override: string | undefined) => string;
50
+ export declare const journalPathFor: (documentPath: string, override: string | undefined) => string;
51
51
  /** Append one line and sync it to disk before returning. */
52
- declare const appendJournal: (journalPath: string, entry: JournalEntry) => Promise<Result<void, FolioCliError>>;
52
+ export declare const appendJournal: (journalPath: string, entry: JournalEntry) => Promise<Result<void, FolioCliError>>;
53
53
  /**
54
54
  * The committed transaction with `txId`, if the journal has one and recovery
55
55
  * did not discard it. Torn or foreign lines (a crash mid-append) are skipped.
56
56
  * A journal (or `.folio`) that is a symlink or hard link is refused.
57
57
  */
58
- declare const findCommit: (journalPath: string, txId: string) => Promise<Result<CommittedTransaction | undefined, FolioCliError>>;
58
+ export declare const findCommit: (journalPath: string, txId: string) => Promise<Result<CommittedTransaction | undefined, FolioCliError>>;
59
59
  /** The newest commit the journal records for one document. */
60
- type LatestCommit = {
60
+ export type LatestCommit = {
61
61
  txId: string;
62
62
  tool: string;
63
63
  author: string;
@@ -71,10 +71,10 @@ type LatestCommit = {
71
71
  * `null`. Reads only through a plain `.folio` directory and never creates
72
72
  * one, so a read-only preview can call it.
73
73
  */
74
- declare const latestCommitFor: (documentPath: string, journalPath?: string) => Promise<LatestCommit | null>;
75
- declare const stagePrefixFor: (documentPath: string) => string;
76
- declare const stagePathFor: (documentPath: string, txId: string) => string;
77
- type RecoveryAction = {
74
+ export declare const latestCommitFor: (documentPath: string, journalPath?: string) => Promise<LatestCommit | null>;
75
+ export declare const stagePrefixFor: (documentPath: string) => string;
76
+ export declare const stagePathFor: (documentPath: string, txId: string) => string;
77
+ export type RecoveryAction = {
78
78
  txId: string;
79
79
  action: "rolledForward";
80
80
  } | {
@@ -93,6 +93,6 @@ type RecoverStagesOptions = {
93
93
  * Removing a discarded stage unlinks the name only; a symlink's target is
94
94
  * never touched.
95
95
  */
96
- declare const recoverStages: ({ documentPath, journalPath, now }: RecoverStagesOptions) => Promise<Result<RecoveryAction[], FolioCliError>>;
96
+ export declare const recoverStages: ({ documentPath, journalPath, now }: RecoverStagesOptions) => Promise<Result<RecoveryAction[], FolioCliError>>;
97
97
  //#endregion
98
- export { CommittedTransaction, JournalCommit, JournalEntry, JournalRecovery, LatestCommit, RECOVERY_DISCARD_REASONS, RecoveryAction, RecoveryDiscardReason, appendJournal, findCommit, journalPathFor, latestCommitFor, recoverStages, stagePathFor, stagePrefixFor };
98
+ export {};
package/dist/lock.d.ts CHANGED
@@ -2,12 +2,12 @@ import { FolioCliError } from "./errors.js";
2
2
  import { Result } from "better-result";
3
3
  //#region src/lock.d.ts
4
4
  /** How long a command-line transaction's lease lasts without renewal. */
5
- declare const TRANSACTION_LEASE_MS: number;
5
+ export declare const TRANSACTION_LEASE_MS: number;
6
6
  /** The owner a lease records when the caller names none. */
7
- declare const DEFAULT_LEASE_OWNER = "folio-cli";
7
+ export declare const DEFAULT_LEASE_OWNER = "folio-cli";
8
8
  /** A lease owner is 1 to 64 letters, digits, '.', '_' or '-'. */
9
- declare const isLeaseOwner: (value: string) => boolean;
10
- type LockHolder = {
9
+ export declare const isLeaseOwner: (value: string) => boolean;
10
+ export type LockHolder = {
11
11
  owner: string;
12
12
  pid: number;
13
13
  host: string;
@@ -20,13 +20,13 @@ type LockHolder = {
20
20
  acceptsFlush?: true;
21
21
  };
22
22
  /** Holder metadata safe to return to a caller that does not own the lease. */
23
- type PublicLockHolder = Omit<LockHolder, "token"> & {
23
+ export type PublicLockHolder = Omit<LockHolder, "token"> & {
24
24
  token?: never;
25
25
  };
26
- declare const publicLockHolder: ({ owner, pid, host, txId, acquiredAt, expiresAt, acceptsFlush }: LockHolder) => PublicLockHolder;
27
- declare const lockPathFor: (documentPath: string) => string;
26
+ export declare const publicLockHolder: ({ owner, pid, host, txId, acquiredAt, expiresAt, acceptsFlush }: LockHolder) => PublicLockHolder;
27
+ export declare const lockPathFor: (documentPath: string) => string;
28
28
  /** What is beside the document: no lock, or a lock with its parsed holder when it has one. */
29
- type LeaseState = {
29
+ export type LeaseState = {
30
30
  type: "free";
31
31
  } | {
32
32
  type: "held";
@@ -41,10 +41,10 @@ type LeaseState = {
41
41
  * held until it is older than a whole lease, so a lock another process is
42
42
  * writing is never taken for abandoned.
43
43
  */
44
- declare const isStaleLease: (state: LeaseState, now: Date) => boolean;
44
+ export declare const isStaleLease: (state: LeaseState, now: Date) => boolean;
45
45
  /** The lease currently beside `documentPath`. A symlinked lock reads as unreadable. */
46
- declare const readLease: (documentPath: string) => Promise<LeaseState>;
47
- type AcquiredLease = {
46
+ export declare const readLease: (documentPath: string) => Promise<LeaseState>;
47
+ export type AcquiredLease = {
48
48
  /** The lock's contents as last written by this handle. */
49
49
  holder: LockHolder;
50
50
  /** Refuse unless the lock still carries this lease's token. */
@@ -67,17 +67,17 @@ type AcquireLeaseOptions = {
67
67
  now?: Date;
68
68
  };
69
69
  /** `.<name>.folio-lock.swap`: held for the instant one process changes an existing lock. */
70
- declare const lockSwapPathFor: (documentPath: string) => string;
70
+ export declare const lockSwapPathFor: (documentPath: string) => string;
71
71
  /**
72
72
  * Act under a lease another call acquired, named by its token: `folio save
73
73
  * --lease-token` from the editor that holds it. Releasing stays with that
74
74
  * holder, so this handle's `release` does nothing.
75
75
  */
76
- declare const adoptLease: (documentPath: string, token: string) => Promise<Result<AcquiredLease, FolioCliError>>;
76
+ export declare const adoptLease: (documentPath: string, token: string) => Promise<Result<AcquiredLease, FolioCliError>>;
77
77
  /**
78
78
  * Take the lease for one transaction. A stale lease is replaced; a live or
79
79
  * unreadable one refuses with `locked` unless `force`.
80
80
  */
81
- declare const acquireLease: ({ documentPath, txId, force, owner, leaseMs, acceptsFlush, now }: AcquireLeaseOptions) => Promise<Result<AcquiredLease, FolioCliError>>;
81
+ export declare const acquireLease: ({ documentPath, txId, force, owner, leaseMs, acceptsFlush, now }: AcquireLeaseOptions) => Promise<Result<AcquiredLease, FolioCliError>>;
82
82
  //#endregion
83
- export { AcquiredLease, DEFAULT_LEASE_OWNER, LeaseState, LockHolder, PublicLockHolder, TRANSACTION_LEASE_MS, acquireLease, adoptLease, isLeaseOwner, isStaleLease, lockPathFor, lockSwapPathFor, publicLockHolder, readLease };
83
+ export {};
package/dist/lock.js CHANGED
@@ -27,7 +27,7 @@ import { setTimeout } from "node:timers/promises";
27
27
  * than a lease. Reads never consult it.
28
28
  */
29
29
  /** How long a command-line transaction's lease lasts without renewal. */
30
- const TRANSACTION_LEASE_MS = 300 * 1e3;
30
+ const TRANSACTION_LEASE_MS = 3e5;
31
31
  /** The owner a lease records when the caller names none. */
32
32
  const DEFAULT_LEASE_OWNER = "folio-cli";
33
33
  const OWNER_PATTERN = /^[\w.-]{1,64}$/u;
@@ -135,9 +135,9 @@ const placeLock = async (lockPath, contents, mode) => {
135
135
  };
136
136
  const encodeHolder = (holder) => encodeUtf8(`${JSON.stringify(holder)}\n`);
137
137
  /** How long a swap lock may stand before another process breaks it (its holder crashed). */
138
- const SWAP_STALE_MS = 10 * 1e3;
138
+ const SWAP_STALE_MS = 1e4;
139
139
  /** How long to wait for another process's swap before refusing. */
140
- const SWAP_WAIT_MS = 5 * 1e3;
140
+ const SWAP_WAIT_MS = 5e3;
141
141
  const SWAP_POLL_MS = 5;
142
142
  /** `.<name>.folio-lock.swap`: held for the instant one process changes an existing lock. */
143
143
  const lockSwapPathFor = (documentPath) => `${lockPathFor(documentPath)}.swap`;