@akagilnc/pi-workflow-roles 0.1.6123 → 0.1.6131
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.
- package/dist/acp-host/production-host.js +15738 -15781
- package/dist/headless-host/description.js +4 -1
- package/dist/headless-host/production-host.js +6215 -6258
- package/dist/public-cli/invocation.js +1 -1
- package/dist/public-cli/main.js +11211 -11254
- package/dist/public-cli/post-admission.js +1 -1
- package/dist/public-cli/run-lifecycle.js +1 -4
- package/dist/role-run-path-rewrite.js +18 -62
- package/dist/role-run-relocation.js +6 -272
- package/dist/run-ticket-number.js +0 -15
- package/dist/ticket-provenance-contracts.js +0 -24
- package/dist/ticket-provenance.js +1 -1
- package/package.json +2 -3
- package/scripts/build-package.mjs +0 -30
- package/src/headless-host/description.ts +4 -1
- package/src/public-cli/invocation.ts +2 -1
- package/src/public-cli/post-admission.ts +2 -1
- package/src/public-cli/run-lifecycle.ts +1 -4
- package/src/role-run-path-rewrite.ts +33 -92
- package/src/role-run-relocation.ts +5 -322
- package/src/run-ticket-number.ts +5 -38
- package/src/ticket-provenance-contracts.ts +0 -32
- package/src/ticket-provenance.ts +1 -1
- package/dist/book-topology-migration-placement.js +0 -404
- package/dist/book-topology-migration.js +0 -125
- package/dist/book-topology-migrators-t11.js +0 -677
- package/dist/book-topology-mixed-volume-migrators.js +0 -322
- package/dist/book-topology-partition-migrators.js +0 -23
- package/dist/book-topology-record-class-migrators.js +0 -671
- package/dist/book-topology-runs-migrator.js +0 -272
- package/dist/migrate-book-topology.js +0 -13982
- package/src/book-topology-migration-placement.ts +0 -501
- package/src/book-topology-migration.ts +0 -213
- package/src/book-topology-migrators-t11.ts +0 -857
- package/src/book-topology-mixed-volume-migrators.ts +0 -453
- package/src/book-topology-partition-migrators.ts +0 -25
- package/src/book-topology-record-class-migrators.ts +0 -882
- package/src/book-topology-runs-migrator.ts +0 -397
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Sole pure authority for typed run-directory path rewrite / projection.
|
|
3
|
-
* No dossier I/O — run-dossier render and role-run-relocation
|
|
4
|
-
*
|
|
3
|
+
* No dossier I/O — run-dossier render and role-run-relocation both consume
|
|
4
|
+
* this module (avoids a cycle through page readers).
|
|
5
5
|
*
|
|
6
6
|
* Scope is typed machine-consumed path fields only — never free text, never
|
|
7
7
|
* caller file-flag path strings.
|
|
@@ -24,21 +24,8 @@ export const ADMITTED_PAGE_PATH_FIELDS = [
|
|
|
24
24
|
"sourceRunPath",
|
|
25
25
|
] as const;
|
|
26
26
|
|
|
27
|
-
export const INVOCATION_PAGE_PATH_FIELDS = [
|
|
28
|
-
"runDirectory",
|
|
29
|
-
"sessionDirectory",
|
|
30
|
-
"sessionFile",
|
|
31
|
-
] as const;
|
|
32
|
-
|
|
33
|
-
export const RUN_STATE_PAGE_PATH_FIELDS = [
|
|
34
|
-
"runDirectory",
|
|
35
|
-
"admittedRequestPath", // pre-#1161 pages only
|
|
36
|
-
"sessionDirectory",
|
|
37
|
-
"sessionFile",
|
|
38
|
-
] as const;
|
|
39
|
-
|
|
40
27
|
/** Typed principal session coordinates rewritten when the owning run leaf moves. */
|
|
41
|
-
|
|
28
|
+
const PRINCIPAL_SESSION_PATH_FIELDS = [
|
|
42
29
|
"sessionDirectory",
|
|
43
30
|
"sessionFile",
|
|
44
31
|
] as const;
|
|
@@ -46,11 +33,6 @@ export const PRINCIPAL_SESSION_PATH_FIELDS = [
|
|
|
46
33
|
const SOURCE_RUN_LOCATOR_FIELDS = ["runDirectory"] as const;
|
|
47
34
|
const SUMMONS_PATH_FIELDS = ["sourceRunPath"] as const;
|
|
48
35
|
|
|
49
|
-
export type RunDirectoryPathRewrite = {
|
|
50
|
-
readonly oldRunDirectory: string;
|
|
51
|
-
readonly newRunDirectory: string;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
36
|
/** Rewrite one path value that points at or under oldRunDirectory. */
|
|
55
37
|
export function rewriteRunDirectoryPathValue(
|
|
56
38
|
value: unknown,
|
|
@@ -66,60 +48,19 @@ export function rewriteRunDirectoryPathValue(
|
|
|
66
48
|
return value;
|
|
67
49
|
}
|
|
68
50
|
|
|
69
|
-
/**
|
|
70
|
-
|
|
71
|
-
* nested run path is not partially claimed by a shorter sibling prefix.
|
|
72
|
-
*/
|
|
73
|
-
export function rewriteRunDirectoryPathValueAgainstRewrites(
|
|
74
|
-
value: unknown,
|
|
75
|
-
rewrites: readonly RunDirectoryPathRewrite[],
|
|
76
|
-
): unknown {
|
|
77
|
-
if (typeof value !== "string" || rewrites.length === 0) return value;
|
|
78
|
-
let best: RunDirectoryPathRewrite | undefined;
|
|
79
|
-
for (const rewrite of rewrites) {
|
|
80
|
-
if (
|
|
81
|
-
value === rewrite.oldRunDirectory ||
|
|
82
|
-
value.startsWith(`${rewrite.oldRunDirectory}${sep}`)
|
|
83
|
-
) {
|
|
84
|
-
if (
|
|
85
|
-
best === undefined ||
|
|
86
|
-
rewrite.oldRunDirectory.length > best.oldRunDirectory.length
|
|
87
|
-
) {
|
|
88
|
-
best = rewrite;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
if (best === undefined) return value;
|
|
93
|
-
return rewriteRunDirectoryPathValue(
|
|
94
|
-
value,
|
|
95
|
-
best.oldRunDirectory,
|
|
96
|
-
best.newRunDirectory,
|
|
97
|
-
);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/** In-place rewrite of selected fields on one record (single pair). */
|
|
101
|
-
export function rewriteRunDirectoryPathFields(
|
|
51
|
+
/** In-place rewrite of selected fields on one record. */
|
|
52
|
+
function rewriteRunDirectoryPathFields(
|
|
102
53
|
record: Record<string, unknown>,
|
|
103
54
|
fields: readonly string[],
|
|
104
55
|
oldRunDirectory: string,
|
|
105
56
|
newRunDirectory: string,
|
|
106
|
-
): void {
|
|
107
|
-
rewriteRunDirectoryPathFieldsAgainstRewrites(record, fields, [
|
|
108
|
-
{ oldRunDirectory, newRunDirectory },
|
|
109
|
-
]);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/** In-place rewrite of selected fields against a rewrite set. */
|
|
113
|
-
export function rewriteRunDirectoryPathFieldsAgainstRewrites(
|
|
114
|
-
record: Record<string, unknown>,
|
|
115
|
-
fields: readonly string[],
|
|
116
|
-
rewrites: readonly RunDirectoryPathRewrite[],
|
|
117
57
|
): void {
|
|
118
58
|
for (const field of fields) {
|
|
119
59
|
if (field in record) {
|
|
120
|
-
record[field] =
|
|
60
|
+
record[field] = rewriteRunDirectoryPathValue(
|
|
121
61
|
record[field],
|
|
122
|
-
|
|
62
|
+
oldRunDirectory,
|
|
63
|
+
newRunDirectory,
|
|
123
64
|
);
|
|
124
65
|
}
|
|
125
66
|
}
|
|
@@ -168,46 +109,49 @@ export function projectTurnRequestLiveRunDirectory(
|
|
|
168
109
|
/** Typed notary/source-run locator: only runDirectory is a path. */
|
|
169
110
|
export function rewriteSourceRunLocator(
|
|
170
111
|
value: unknown,
|
|
171
|
-
|
|
112
|
+
oldRunDirectory: string,
|
|
113
|
+
newRunDirectory: string,
|
|
172
114
|
): void {
|
|
173
115
|
if (!isRecord(value)) return;
|
|
174
|
-
|
|
116
|
+
rewriteRunDirectoryPathFields(
|
|
175
117
|
value,
|
|
176
118
|
SOURCE_RUN_LOCATOR_FIELDS,
|
|
177
|
-
|
|
119
|
+
oldRunDirectory,
|
|
120
|
+
newRunDirectory,
|
|
178
121
|
);
|
|
179
122
|
}
|
|
180
123
|
|
|
181
124
|
/** Same-ticket summons materials: typed source-run; caller attach paths stay as-is (#1165). */
|
|
182
|
-
|
|
125
|
+
function rewriteSummonsMaterials(
|
|
183
126
|
value: unknown,
|
|
184
|
-
|
|
127
|
+
oldRunDirectory: string,
|
|
128
|
+
newRunDirectory: string,
|
|
185
129
|
): void {
|
|
186
130
|
if (!isRecord(value)) return;
|
|
187
|
-
|
|
131
|
+
rewriteRunDirectoryPathFields(
|
|
188
132
|
value,
|
|
189
133
|
SUMMONS_PATH_FIELDS,
|
|
190
|
-
|
|
134
|
+
oldRunDirectory,
|
|
135
|
+
newRunDirectory,
|
|
191
136
|
);
|
|
192
|
-
rewriteSourceRunLocator(value.sourceRun,
|
|
137
|
+
rewriteSourceRunLocator(value.sourceRun, oldRunDirectory, newRunDirectory);
|
|
193
138
|
// #1165: summons.attachmentPaths are caller paths — do not rewrite.
|
|
194
139
|
}
|
|
195
140
|
|
|
196
141
|
/** Project one admitted page in memory after its containing run moved. */
|
|
197
142
|
export function rewriteAdmittedRoleRunPage(
|
|
198
143
|
page: Record<string, unknown>,
|
|
199
|
-
|
|
144
|
+
oldRunDirectory: string,
|
|
145
|
+
newRunDirectory: string,
|
|
200
146
|
): void {
|
|
201
|
-
|
|
202
|
-
|
|
147
|
+
rewriteRunDirectoryPathFields(
|
|
148
|
+
page,
|
|
149
|
+
ADMITTED_PAGE_PATH_FIELDS,
|
|
150
|
+
oldRunDirectory,
|
|
151
|
+
newRunDirectory,
|
|
152
|
+
);
|
|
153
|
+
rewriteSourceRunLocator(page.sourceRun, oldRunDirectory, newRunDirectory);
|
|
203
154
|
// #1165: admitted attachments are caller paths outside the run directory — do not rewrite.
|
|
204
|
-
if (isRecord(page.principal)) {
|
|
205
|
-
rewriteRunDirectoryPathFieldsAgainstRewrites(
|
|
206
|
-
page.principal,
|
|
207
|
-
PRINCIPAL_SESSION_PATH_FIELDS,
|
|
208
|
-
rewrites,
|
|
209
|
-
);
|
|
210
|
-
}
|
|
211
155
|
}
|
|
212
156
|
|
|
213
157
|
/**
|
|
@@ -225,14 +169,11 @@ export function projectRenderedPagePaths(
|
|
|
225
169
|
: undefined;
|
|
226
170
|
if (stored === undefined || stored === actualRunDirectory) return page;
|
|
227
171
|
const projected = structuredClone(page);
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
// Admitted field set is the location-field superset of invocation; runState adds
|
|
232
|
-
// principal (covered) and optional currentCourt summons under this run.
|
|
233
|
-
rewriteAdmittedRoleRunPage(projected, rewrites);
|
|
172
|
+
// Admitted field set is the location-field superset of invocation and runState;
|
|
173
|
+
// runState adds optional currentCourt summons under this run.
|
|
174
|
+
rewriteAdmittedRoleRunPage(projected, stored, actualRunDirectory);
|
|
234
175
|
if (isRecord(projected.currentCourt)) {
|
|
235
|
-
rewriteSummonsMaterials(projected.currentCourt.summons,
|
|
176
|
+
rewriteSummonsMaterials(projected.currentCourt.summons, stored, actualRunDirectory);
|
|
236
177
|
}
|
|
237
178
|
return projected;
|
|
238
179
|
}
|
|
@@ -1,54 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* (sole authority); this module owns I/O walks that need dossier page readers.
|
|
5
|
-
*
|
|
6
|
-
* Scope is typed machine-consumed path fields only — never free text, never
|
|
7
|
-
* caller file-flag path strings. Nested walk is confined to package-owned
|
|
8
|
-
* `session/` seams.
|
|
2
|
+
* Retained-path matching for live lookup. Pure path rewrite rules live in
|
|
3
|
+
* role-run-path-rewrite.ts (sole authority) and are re-exported here.
|
|
9
4
|
*/
|
|
10
|
-
import {
|
|
11
|
-
import { dirname, join } from "node:path";
|
|
5
|
+
import { dirname } from "node:path";
|
|
12
6
|
|
|
13
7
|
import { activationBookDirectory, physicalPathIdentity } from "./activation-ledger-topology.ts";
|
|
14
|
-
import { AUDITOR_PARENT_ATTEMPT_BINDING_ENTRY_TYPE } from "./compliance-transport.ts";
|
|
15
8
|
import { readRoleRunIdentity } from "./public-cli/run-lifecycle.ts";
|
|
16
|
-
import { roleRunPlacement
|
|
17
|
-
import {
|
|
18
|
-
INVOCATION_PAGE_PATH_FIELDS,
|
|
19
|
-
PRINCIPAL_SESSION_PATH_FIELDS,
|
|
20
|
-
RUN_STATE_PAGE_PATH_FIELDS,
|
|
21
|
-
type RunDirectoryPathRewrite,
|
|
22
|
-
projectTurnRequestLiveRunDirectory,
|
|
23
|
-
rewriteAdmittedRoleRunPage,
|
|
24
|
-
rewritePrincipalSessionPaths,
|
|
25
|
-
rewriteRunDirectoryPathFields,
|
|
26
|
-
rewriteRunDirectoryPathFieldsAgainstRewrites,
|
|
27
|
-
rewriteRunDirectoryPathValue,
|
|
28
|
-
rewriteRunDirectoryPathValueAgainstRewrites,
|
|
29
|
-
rewriteSummonsMaterials,
|
|
30
|
-
} from "./role-run-path-rewrite.ts";
|
|
31
|
-
import { readPageSync, updateSectionSync } from "./run-dossier.ts";
|
|
32
|
-
import { isEnoent, isRecord } from "./unknown-value.ts";
|
|
9
|
+
import { roleRunPlacement } from "./role-run-placement.ts";
|
|
10
|
+
import { rewriteRunDirectoryPathValue } from "./role-run-path-rewrite.ts";
|
|
33
11
|
|
|
34
12
|
// Re-export the pure path API so existing import sites stay on this module path.
|
|
35
13
|
export {
|
|
36
|
-
PRINCIPAL_SESSION_PATH_FIELDS,
|
|
37
|
-
type RunDirectoryPathRewrite,
|
|
38
14
|
projectTurnRequestLiveRunDirectory,
|
|
39
15
|
rewriteAdmittedRoleRunPage,
|
|
40
16
|
rewritePrincipalSessionPaths,
|
|
41
|
-
rewriteRunDirectoryPathFields,
|
|
42
|
-
rewriteRunDirectoryPathFieldsAgainstRewrites,
|
|
43
17
|
rewriteRunDirectoryPathValue,
|
|
44
|
-
rewriteRunDirectoryPathValueAgainstRewrites,
|
|
45
18
|
} from "./role-run-path-rewrite.ts";
|
|
46
19
|
|
|
47
|
-
const OFFICER_POINTER_FIELDS = ["sessionFile", "runDirectory"] as const;
|
|
48
|
-
const SITIAN_RECORD_FIELDS = ["sessionParent"] as const;
|
|
49
|
-
const SESSION_HEADER_FIELDS = ["parentSession"] as const;
|
|
50
|
-
const BINDING_PARENT_FIELDS = ["sessionFile"] as const;
|
|
51
|
-
|
|
52
20
|
/** Match physical aliases or a normal unbound→ticket bind, never historical migration layouts. */
|
|
53
21
|
export async function retainedRunPathsMatch(
|
|
54
22
|
recordedPath: unknown,
|
|
@@ -82,288 +50,3 @@ export async function retainedRunPathsMatch(
|
|
|
82
50
|
}
|
|
83
51
|
return false;
|
|
84
52
|
}
|
|
85
|
-
|
|
86
|
-
function collectRewrites(input: {
|
|
87
|
-
readonly oldRunDirectory: string;
|
|
88
|
-
readonly newRunDirectory: string;
|
|
89
|
-
readonly crossRunRewrites?: readonly RunDirectoryPathRewrite[];
|
|
90
|
-
}): readonly RunDirectoryPathRewrite[] {
|
|
91
|
-
const own: RunDirectoryPathRewrite = {
|
|
92
|
-
oldRunDirectory: input.oldRunDirectory,
|
|
93
|
-
newRunDirectory: input.newRunDirectory,
|
|
94
|
-
};
|
|
95
|
-
if (
|
|
96
|
-
input.crossRunRewrites === undefined ||
|
|
97
|
-
input.crossRunRewrites.length === 0
|
|
98
|
-
) {
|
|
99
|
-
return [own];
|
|
100
|
-
}
|
|
101
|
-
// Own pair first; duplicates of the same old path keep the first (own) target.
|
|
102
|
-
const seen = new Set<string>([own.oldRunDirectory]);
|
|
103
|
-
const out: RunDirectoryPathRewrite[] = [own];
|
|
104
|
-
for (const rewrite of input.crossRunRewrites) {
|
|
105
|
-
if (seen.has(rewrite.oldRunDirectory)) continue;
|
|
106
|
-
seen.add(rewrite.oldRunDirectory);
|
|
107
|
-
out.push(rewrite);
|
|
108
|
-
}
|
|
109
|
-
return out;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/** Pre-#1161 `session/auditor-roles/<officer>.pointer.json` (migrator input only). */
|
|
113
|
-
async function rewriteLegacyOfficerPointerFile(
|
|
114
|
-
path: string,
|
|
115
|
-
rewrites: readonly RunDirectoryPathRewrite[],
|
|
116
|
-
): Promise<void> {
|
|
117
|
-
const page = JSON.parse(await readFile(path, "utf8")) as unknown;
|
|
118
|
-
if (!isRecord(page) || page.kind !== "direct-officer-run-pointer") return;
|
|
119
|
-
const before = JSON.stringify(page);
|
|
120
|
-
rewriteRunDirectoryPathFieldsAgainstRewrites(page, OFFICER_POINTER_FIELDS, rewrites);
|
|
121
|
-
if (JSON.stringify(page) !== before) await writeFile(path, `${JSON.stringify(page)}\n`, "utf8");
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
async function rewriteSitianRecordsJsonl(
|
|
125
|
-
path: string,
|
|
126
|
-
rewrites: readonly RunDirectoryPathRewrite[],
|
|
127
|
-
): Promise<void> {
|
|
128
|
-
let raw: string;
|
|
129
|
-
try {
|
|
130
|
-
raw = await readFile(path, "utf8");
|
|
131
|
-
} catch (error) {
|
|
132
|
-
if (isEnoent(error)) return;
|
|
133
|
-
throw error;
|
|
134
|
-
}
|
|
135
|
-
if (raw.length === 0) return;
|
|
136
|
-
const endsWithNewline = raw.endsWith("\n");
|
|
137
|
-
const lines = raw.split("\n");
|
|
138
|
-
// split keeps a trailing empty slot when file ends with \n — preserve it.
|
|
139
|
-
let changed = false;
|
|
140
|
-
const out: string[] = [];
|
|
141
|
-
for (let i = 0; i < lines.length; i += 1) {
|
|
142
|
-
const line = lines[i]!;
|
|
143
|
-
if (line === "" && i === lines.length - 1 && endsWithNewline) {
|
|
144
|
-
out.push("");
|
|
145
|
-
continue;
|
|
146
|
-
}
|
|
147
|
-
if (line.trim() === "") {
|
|
148
|
-
out.push(line);
|
|
149
|
-
continue;
|
|
150
|
-
}
|
|
151
|
-
let parsed: unknown;
|
|
152
|
-
try {
|
|
153
|
-
parsed = JSON.parse(line);
|
|
154
|
-
} catch {
|
|
155
|
-
out.push(line);
|
|
156
|
-
continue;
|
|
157
|
-
}
|
|
158
|
-
if (!isRecord(parsed)) {
|
|
159
|
-
out.push(line);
|
|
160
|
-
continue;
|
|
161
|
-
}
|
|
162
|
-
if (!("sessionParent" in parsed)) {
|
|
163
|
-
out.push(line);
|
|
164
|
-
continue;
|
|
165
|
-
}
|
|
166
|
-
const before = parsed.sessionParent;
|
|
167
|
-
rewriteRunDirectoryPathFieldsAgainstRewrites(
|
|
168
|
-
parsed,
|
|
169
|
-
SITIAN_RECORD_FIELDS,
|
|
170
|
-
rewrites,
|
|
171
|
-
);
|
|
172
|
-
if (parsed.sessionParent !== before) changed = true;
|
|
173
|
-
out.push(JSON.stringify(parsed));
|
|
174
|
-
}
|
|
175
|
-
if (!changed) return;
|
|
176
|
-
const body = out.join("\n");
|
|
177
|
-
await writeFile(
|
|
178
|
-
path,
|
|
179
|
-
endsWithNewline && !body.endsWith("\n") ? `${body}\n` : body,
|
|
180
|
-
"utf8",
|
|
181
|
-
);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Session transcript typed locators only: header.parentSession and
|
|
186
|
-
* ak_auditor_parent_attempt_binding data.parent.sessionFile. Never message text.
|
|
187
|
-
*/
|
|
188
|
-
async function rewriteSessionTranscriptBindings(
|
|
189
|
-
path: string,
|
|
190
|
-
rewrites: readonly RunDirectoryPathRewrite[],
|
|
191
|
-
): Promise<void> {
|
|
192
|
-
let raw: string;
|
|
193
|
-
try {
|
|
194
|
-
raw = await readFile(path, "utf8");
|
|
195
|
-
} catch (error) {
|
|
196
|
-
if (isEnoent(error)) return;
|
|
197
|
-
throw error;
|
|
198
|
-
}
|
|
199
|
-
if (raw.length === 0) return;
|
|
200
|
-
const endsWithNewline = raw.endsWith("\n");
|
|
201
|
-
const lines = raw.split("\n");
|
|
202
|
-
let changed = false;
|
|
203
|
-
const out: string[] = [];
|
|
204
|
-
for (let i = 0; i < lines.length; i += 1) {
|
|
205
|
-
const line = lines[i]!;
|
|
206
|
-
if (line === "" && i === lines.length - 1 && endsWithNewline) {
|
|
207
|
-
out.push("");
|
|
208
|
-
continue;
|
|
209
|
-
}
|
|
210
|
-
if (line.trim() === "") {
|
|
211
|
-
out.push(line);
|
|
212
|
-
continue;
|
|
213
|
-
}
|
|
214
|
-
let parsed: unknown;
|
|
215
|
-
try {
|
|
216
|
-
parsed = JSON.parse(line);
|
|
217
|
-
} catch {
|
|
218
|
-
out.push(line);
|
|
219
|
-
continue;
|
|
220
|
-
}
|
|
221
|
-
if (!isRecord(parsed)) {
|
|
222
|
-
out.push(line);
|
|
223
|
-
continue;
|
|
224
|
-
}
|
|
225
|
-
let lineChanged = false;
|
|
226
|
-
if (parsed.type === "session" && "parentSession" in parsed) {
|
|
227
|
-
const before = parsed.parentSession;
|
|
228
|
-
rewriteRunDirectoryPathFieldsAgainstRewrites(
|
|
229
|
-
parsed,
|
|
230
|
-
SESSION_HEADER_FIELDS,
|
|
231
|
-
rewrites,
|
|
232
|
-
);
|
|
233
|
-
if (parsed.parentSession !== before) lineChanged = true;
|
|
234
|
-
} else if (
|
|
235
|
-
parsed.type === "custom" &&
|
|
236
|
-
parsed.customType === AUDITOR_PARENT_ATTEMPT_BINDING_ENTRY_TYPE &&
|
|
237
|
-
isRecord(parsed.data) &&
|
|
238
|
-
isRecord(parsed.data.parent)
|
|
239
|
-
) {
|
|
240
|
-
const parent = parsed.data.parent;
|
|
241
|
-
const before = parent.sessionFile;
|
|
242
|
-
rewriteRunDirectoryPathFieldsAgainstRewrites(
|
|
243
|
-
parent,
|
|
244
|
-
BINDING_PARENT_FIELDS,
|
|
245
|
-
rewrites,
|
|
246
|
-
);
|
|
247
|
-
if (parent.sessionFile !== before) lineChanged = true;
|
|
248
|
-
}
|
|
249
|
-
if (lineChanged) changed = true;
|
|
250
|
-
out.push(lineChanged ? JSON.stringify(parsed) : line);
|
|
251
|
-
}
|
|
252
|
-
if (!changed) return;
|
|
253
|
-
const body = out.join("\n");
|
|
254
|
-
await writeFile(
|
|
255
|
-
path,
|
|
256
|
-
endsWithNewline && !body.endsWith("\n") ? `${body}\n` : body,
|
|
257
|
-
"utf8",
|
|
258
|
-
);
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* Package-owned nested seams under session/ only:
|
|
263
|
-
* sitian records.jsonl,
|
|
264
|
-
* session transcript typed parent bindings. Never walks caller file paths.
|
|
265
|
-
*/
|
|
266
|
-
async function rewriteNestedMachinePathPages(
|
|
267
|
-
pagesDirectory: string,
|
|
268
|
-
rewrites: readonly RunDirectoryPathRewrite[],
|
|
269
|
-
): Promise<void> {
|
|
270
|
-
const sessionRoot = sessionDirectoryOf(pagesDirectory);
|
|
271
|
-
async function walk(directory: string): Promise<void> {
|
|
272
|
-
let entries;
|
|
273
|
-
try {
|
|
274
|
-
entries = await readdir(directory, { withFileTypes: true });
|
|
275
|
-
} catch (error) {
|
|
276
|
-
if (isEnoent(error)) return;
|
|
277
|
-
throw error;
|
|
278
|
-
}
|
|
279
|
-
for (const entry of entries) {
|
|
280
|
-
const path = join(directory, entry.name);
|
|
281
|
-
if (entry.isDirectory()) {
|
|
282
|
-
await walk(path);
|
|
283
|
-
continue;
|
|
284
|
-
}
|
|
285
|
-
if (!entry.isFile()) continue;
|
|
286
|
-
if (entry.name.endsWith(".pointer.json")) {
|
|
287
|
-
await rewriteLegacyOfficerPointerFile(path, rewrites);
|
|
288
|
-
} else if (entry.name === "records.jsonl") {
|
|
289
|
-
await rewriteSitianRecordsJsonl(path, rewrites);
|
|
290
|
-
} else if (entry.name.endsWith(".jsonl")) {
|
|
291
|
-
await rewriteSessionTranscriptBindings(path, rewrites);
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
await walk(sessionRoot);
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
/**
|
|
299
|
-
* Rewrite the admitted / invocation / runState fact rows (typed run placement
|
|
300
|
-
* paths only; caller --attach / --request-manifest paths stay as-is, #1165),
|
|
301
|
-
* then nested package-owned session seams. Callers may rewrite before or after
|
|
302
|
-
* the filesystem move/copy: `pagesDirectory` is where the pages currently live
|
|
303
|
-
* on disk; path strings that still name `oldRunDirectory` become
|
|
304
|
-
* `newRunDirectory`. `crossRunRewrites` covers officer/parent pointers that
|
|
305
|
-
* landed under a different final placement.
|
|
306
|
-
*/
|
|
307
|
-
export async function rewriteRoleRunDurablePages(input: {
|
|
308
|
-
readonly pagesDirectory: string;
|
|
309
|
-
readonly oldRunDirectory: string;
|
|
310
|
-
readonly newRunDirectory: string;
|
|
311
|
-
readonly crossRunRewrites?: readonly RunDirectoryPathRewrite[];
|
|
312
|
-
}): Promise<void> {
|
|
313
|
-
const { pagesDirectory } = input;
|
|
314
|
-
const rewrites = collectRewrites(input);
|
|
315
|
-
|
|
316
|
-
// One rewriter per page kind; each keeps its own field list.
|
|
317
|
-
const pageRewriters: Readonly<Record<"admitted" | "invocation" | "runState", (page: Record<string, unknown>) => void>> = {
|
|
318
|
-
admitted: (page) => rewriteAdmittedRoleRunPage(page, rewrites),
|
|
319
|
-
invocation: (page) =>
|
|
320
|
-
rewriteRunDirectoryPathFieldsAgainstRewrites(page, INVOCATION_PAGE_PATH_FIELDS, rewrites),
|
|
321
|
-
runState: (page) => {
|
|
322
|
-
rewriteRunDirectoryPathFieldsAgainstRewrites(page, RUN_STATE_PAGE_PATH_FIELDS, rewrites);
|
|
323
|
-
if (isRecord(page.principal)) {
|
|
324
|
-
rewriteRunDirectoryPathFieldsAgainstRewrites(
|
|
325
|
-
page.principal,
|
|
326
|
-
PRINCIPAL_SESSION_PATH_FIELDS,
|
|
327
|
-
rewrites,
|
|
328
|
-
);
|
|
329
|
-
}
|
|
330
|
-
// Open court summons: source-run locators only; caller attach paths stay (#1165).
|
|
331
|
-
if (isRecord(page.currentCourt)) {
|
|
332
|
-
rewriteSummonsMaterials(page.currentCourt.summons, rewrites);
|
|
333
|
-
}
|
|
334
|
-
},
|
|
335
|
-
};
|
|
336
|
-
// A page is rewritten only when its fact row exists — never gate on the rendering.
|
|
337
|
-
for (const [section, rewrite] of Object.entries(pageRewriters) as [keyof typeof pageRewriters, (page: Record<string, unknown>) => void][]) {
|
|
338
|
-
if (readPageSync(pagesDirectory, section) === undefined) continue;
|
|
339
|
-
updateSectionSync(pagesDirectory, section, (current) => {
|
|
340
|
-
const page = structuredClone(current);
|
|
341
|
-
rewrite(page);
|
|
342
|
-
return JSON.stringify(page) === JSON.stringify(current) ? undefined : page;
|
|
343
|
-
});
|
|
344
|
-
}
|
|
345
|
-
// Runs from before #1161 (the one-shot book-topology migrator's input) keep these
|
|
346
|
-
// as separate page files; the same rewriters apply. Nothing live writes them.
|
|
347
|
-
for (const [file, rewrite] of [
|
|
348
|
-
["admitted-request.json", pageRewriters.admitted],
|
|
349
|
-
["invocation.json", pageRewriters.invocation],
|
|
350
|
-
["run-state.json", pageRewriters.runState],
|
|
351
|
-
] as const) {
|
|
352
|
-
const path = join(pagesDirectory, file);
|
|
353
|
-
let raw: string;
|
|
354
|
-
try {
|
|
355
|
-
raw = await readFile(path, "utf8");
|
|
356
|
-
} catch (error) {
|
|
357
|
-
if (isEnoent(error)) continue;
|
|
358
|
-
throw error;
|
|
359
|
-
}
|
|
360
|
-
const page = JSON.parse(raw) as Record<string, unknown>;
|
|
361
|
-
const before = JSON.stringify(page);
|
|
362
|
-
rewrite(page);
|
|
363
|
-
if (JSON.stringify(page) !== before) {
|
|
364
|
-
await writeFile(path, `${JSON.stringify(page, null, 2)}\n`, "utf8");
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
await rewriteNestedMachinePathPages(pagesDirectory, rewrites);
|
|
369
|
-
}
|
package/src/run-ticket-number.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Typed ticketNumber reader for a retained run's durable pages.
|
|
3
|
-
*
|
|
4
|
-
* Pre-#1161 page files are readable only via readMigrationBoardTicketNumber.
|
|
3
|
+
* Board reads use state.jsonl rows only (admitted, then invocation).
|
|
5
4
|
* Migration derivation page last so worktree-derived placement stays readable
|
|
6
5
|
* without forging a board assertion. Missing page (ENOENT) → try next / undefined;
|
|
7
6
|
* damage and non-ENOENT IO failures propagate.
|
|
@@ -13,7 +12,7 @@ import { join } from "node:path";
|
|
|
13
12
|
import { isEnoent, isRecord } from "./unknown-value.ts";
|
|
14
13
|
|
|
15
14
|
/** Sole on-disk page for worktree-basename ticket derivation (#865). */
|
|
16
|
-
|
|
15
|
+
const MIGRATION_TICKET_DERIVATION_PAGE =
|
|
17
16
|
"migration-ticket-derivation.json" as const;
|
|
18
17
|
|
|
19
18
|
/** Positive-integer contract for display / snapshot inputs; binding uses the safe subset below. */
|
|
@@ -32,7 +31,7 @@ export function isTicketNumberString(value: unknown): value is string {
|
|
|
32
31
|
}
|
|
33
32
|
|
|
34
33
|
/**
|
|
35
|
-
* Ticket spelling shared by placement
|
|
34
|
+
* Ticket spelling shared by placement and sitian subject routing.
|
|
36
35
|
* A number, or a digit string with no sign, zero-pad, decimal, or `#`.
|
|
37
36
|
* Unsafe integers are unidentified. Leading `#N` stays on readDeclaredTicketNumber.
|
|
38
37
|
*/
|
|
@@ -113,12 +112,6 @@ async function readJsonObject(
|
|
|
113
112
|
}
|
|
114
113
|
}
|
|
115
114
|
|
|
116
|
-
/** Pre-#1161 separate board pages — migration input only, not a runtime fact path. */
|
|
117
|
-
const LEGACY_BOARD_PAGE: Readonly<Record<"admitted" | "invocation", string>> = {
|
|
118
|
-
admitted: "admitted-request.json",
|
|
119
|
-
invocation: "invocation.json",
|
|
120
|
-
};
|
|
121
|
-
|
|
122
115
|
function readBoardPageTicketNumberFromRows(
|
|
123
116
|
runDirectory: string,
|
|
124
117
|
section: "admitted" | "invocation",
|
|
@@ -127,15 +120,6 @@ function readBoardPageTicketNumberFromRows(
|
|
|
127
120
|
return fromRows === undefined ? undefined : ticketFromRecord(fromRows);
|
|
128
121
|
}
|
|
129
122
|
|
|
130
|
-
async function readBoardPageTicketNumberFromLegacy(
|
|
131
|
-
runDirectory: string,
|
|
132
|
-
section: "admitted" | "invocation",
|
|
133
|
-
): Promise<number | undefined> {
|
|
134
|
-
const record = await readJsonObject(join(runDirectory, LEGACY_BOARD_PAGE[section]));
|
|
135
|
-
if (record === undefined) return undefined;
|
|
136
|
-
return ticketFromRecord(record);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
123
|
/**
|
|
140
124
|
* Board-only ticketNumber from fact rows (admitted → invocation).
|
|
141
125
|
* Public / production identity paths use this sole projection — never legacy pages.
|
|
@@ -149,25 +133,8 @@ export async function readBoardTicketNumber(
|
|
|
149
133
|
);
|
|
150
134
|
}
|
|
151
135
|
|
|
152
|
-
/**
|
|
153
|
-
|
|
154
|
-
* Only #852 migrators and placement may call this; runtime identity must not.
|
|
155
|
-
*/
|
|
156
|
-
export async function readMigrationBoardTicketNumber(
|
|
157
|
-
runDirectory: string,
|
|
158
|
-
): Promise<number | undefined> {
|
|
159
|
-
return (
|
|
160
|
-
(await readBoardTicketNumber(runDirectory)) ??
|
|
161
|
-
(await readBoardPageTicketNumberFromLegacy(runDirectory, "admitted")) ??
|
|
162
|
-
(await readBoardPageTicketNumberFromLegacy(runDirectory, "invocation"))
|
|
163
|
-
);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Worktree-derivation ticket only — never a board assertion. Callers that must
|
|
168
|
-
* distinguish board vs derived use this; effective readers use readRunTicketNumber.
|
|
169
|
-
*/
|
|
170
|
-
export async function readMigrationDerivedTicketNumber(
|
|
136
|
+
/** Worktree-derivation ticket only — never a board assertion. */
|
|
137
|
+
async function readMigrationDerivedTicketNumber(
|
|
171
138
|
runDirectory: string,
|
|
172
139
|
): Promise<number | undefined> {
|
|
173
140
|
const record = await readJsonObject(
|
|
@@ -39,15 +39,6 @@ export type TicketProvenanceSession = {
|
|
|
39
39
|
readonly ranges: readonly TicketProvenanceRange[];
|
|
40
40
|
};
|
|
41
41
|
|
|
42
|
-
/** 旧 snapshot 册子头形状(存量可读;#1090 后新提交不再维护折叠头)。 */
|
|
43
|
-
export type TicketProvenanceHeader = {
|
|
44
|
-
readonly repo: string;
|
|
45
|
-
readonly ticket: number | null;
|
|
46
|
-
readonly createdAt: string;
|
|
47
|
-
readonly updatedAt: string;
|
|
48
|
-
readonly sessions: readonly TicketProvenanceSession[];
|
|
49
|
-
};
|
|
50
|
-
|
|
51
42
|
/**
|
|
52
43
|
* 一条对话(存于不可变投影提交;旧 snapshot 中也可为裸行)。
|
|
53
44
|
* `id` 按源事实存在则记、不存在不编;`s` 为本轮 sessions 下标。
|
|
@@ -106,26 +97,3 @@ export function projectTicketProvenanceSessions(
|
|
|
106
97
|
}
|
|
107
98
|
return sessions;
|
|
108
99
|
}
|
|
109
|
-
|
|
110
|
-
/** 读回册子头(文件第一行)。形状不成立即 undefined——按无册处理,不猜。 */
|
|
111
|
-
export function projectTicketProvenanceHeader(
|
|
112
|
-
value: unknown,
|
|
113
|
-
): TicketProvenanceHeader | undefined {
|
|
114
|
-
if (!isRecord(value)) return undefined;
|
|
115
|
-
const ticket = value.ticket === null ? null : positiveInteger(value.ticket);
|
|
116
|
-
if (ticket === undefined) return undefined;
|
|
117
|
-
if (typeof value.repo !== "string") return undefined;
|
|
118
|
-
if (typeof value.createdAt !== "string" || typeof value.updatedAt !== "string") {
|
|
119
|
-
return undefined;
|
|
120
|
-
}
|
|
121
|
-
// Malformed sessions stay unusable — do not wash into lawful empty (失败诚实).
|
|
122
|
-
const sessions = projectTicketProvenanceSessions(value.sessions);
|
|
123
|
-
if (sessions === undefined) return undefined;
|
|
124
|
-
return {
|
|
125
|
-
repo: value.repo,
|
|
126
|
-
ticket,
|
|
127
|
-
createdAt: value.createdAt,
|
|
128
|
-
updatedAt: value.updatedAt,
|
|
129
|
-
sessions,
|
|
130
|
-
};
|
|
131
|
-
}
|
package/src/ticket-provenance.ts
CHANGED
|
@@ -156,7 +156,7 @@ export async function rehomeUnboundTicketProvenance(
|
|
|
156
156
|
|
|
157
157
|
// Live staging: ticket-provenance rows in the run's history.jsonl. Append-only
|
|
158
158
|
// history keeps the staging rows; the ticket-root diary is the home.
|
|
159
|
-
// Old run/records.jsonl is not a runtime input (#1161)
|
|
159
|
+
// Old run/records.jsonl is not a runtime input (#1161).
|
|
160
160
|
let history: string;
|
|
161
161
|
try {
|
|
162
162
|
history = await readFile(join(runDirectory, RUN_HISTORY_FILE), "utf8");
|