@akagilnc/pi-workflow-roles 0.1.4295 → 0.1.4321

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.
@@ -1,91 +0,0 @@
1
- /**
2
- * Sitian whole-file volume I/O (ADR 0065 records-owner / record-entry).
3
- *
4
- * Owns destination resolution, create, raw read, and whole-file rewrite for
5
- * kinds whose persistence shape is not the appender SitianRecord row
6
- * (ticket-provenance header + bare dialogue lines, #901). Appender kernel
7
- * stays append-only; this module does not restore append watermarks.
8
- */
9
- import { appendFileSync } from "node:fs";
10
- import { readFile } from "node:fs/promises";
11
-
12
- import {
13
- ensureRealDirectoryTree,
14
- errorText,
15
- } from "./activation-ledger-topology.ts";
16
- import { writeFileAtomically } from "./atomic-write.ts";
17
- import { resolveSitianRecordPath } from "./sitian-appender.ts";
18
- import {
19
- SitianInfrastructureError,
20
- type SitianRecordInput,
21
- } from "./sitian-contracts.ts";
22
-
23
- export type SitianVolumePath = {
24
- readonly recordFile: string;
25
- readonly volumeDir: string;
26
- };
27
-
28
- /** Resolve a volume path from ambient topology — callers never pick the destination. */
29
- export function resolveSitianVolume(input: SitianRecordInput): SitianVolumePath {
30
- const path = resolveSitianRecordPath(input);
31
- return { recordFile: path.recordFile, volumeDir: path.sessionDir };
32
- }
33
-
34
- /**
35
- * Ensure the volume directory + file exist.
36
- * Append-open creates an absent volume without truncating concurrent first writers.
37
- */
38
- export function ensureSitianVolume(input: SitianRecordInput): SitianVolumePath {
39
- try {
40
- const { sessionDir, recordFile, ledgerHome } = resolveSitianRecordPath(input);
41
- ensureRealDirectoryTree(ledgerHome, sessionDir);
42
- appendFileSync(recordFile, "", "utf8");
43
- return { recordFile, volumeDir: sessionDir };
44
- } catch (error) {
45
- if (error instanceof SitianInfrastructureError) throw error;
46
- throw new SitianInfrastructureError(
47
- `Sitian volume ensure failure: ${errorText(error)}`,
48
- { cause: error },
49
- );
50
- }
51
- }
52
-
53
- /** Raw volume text. Absent file → text undefined (not an error). */
54
- export async function readSitianVolumeText(
55
- input: SitianRecordInput,
56
- ): Promise<{ readonly recordFile: string; readonly text: string | undefined }> {
57
- const { recordFile } = resolveSitianVolume(input);
58
- try {
59
- return { recordFile, text: await readFile(recordFile, "utf8") };
60
- } catch (error) {
61
- if ((error as NodeJS.ErrnoException).code === "ENOENT") {
62
- return { recordFile, text: undefined };
63
- }
64
- throw new SitianInfrastructureError(
65
- `Sitian volume read failure: ${errorText(error)}`,
66
- { cause: error },
67
- );
68
- }
69
- }
70
-
71
- /**
72
- * Replace the entire volume body (whole-file reproject).
73
- * Same-directory temp + rename — never truncate the live inode in place
74
- * (#901 sole diary; reuse atomic-write, no parallel persist mechanism).
75
- * Not append; no identity claim / torn-tail watermark — those stay on appender.
76
- */
77
- export async function rewriteSitianVolume(
78
- input: SitianRecordInput & { readonly body: string },
79
- ): Promise<SitianVolumePath> {
80
- try {
81
- const volume = ensureSitianVolume(input);
82
- await writeFileAtomically(volume.recordFile, input.body);
83
- return volume;
84
- } catch (error) {
85
- if (error instanceof SitianInfrastructureError) throw error;
86
- throw new SitianInfrastructureError(
87
- `Sitian volume rewrite failure: ${errorText(error)}`,
88
- { cause: error },
89
- );
90
- }
91
- }