@akagilnc/pi-workflow-roles 0.1.6126 → 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/production-host.js +6214 -6257
- 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/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
|
@@ -84,7 +84,7 @@ export async function refreshAdmittedPlacementAfterHostTurn(admitted, authority,
|
|
|
84
84
|
const coords = { ...authority.decode(admitted.principal) };
|
|
85
85
|
rewritePrincipalSessionPaths(coords, oldRunDirectory, found);
|
|
86
86
|
const principal = authority.seal(coords);
|
|
87
|
-
rewriteAdmittedRoleRunPage(admitted,
|
|
87
|
+
rewriteAdmittedRoleRunPage(admitted, oldRunDirectory, found);
|
|
88
88
|
admitted.principal = principal;
|
|
89
89
|
heldLease?.relocate(found);
|
|
90
90
|
relocation = { oldRunDirectory, newRunDirectory: found };
|
|
@@ -791,10 +791,7 @@ async function loadResumableRunRecord(home, runId, authority, knownRunDirectory)
|
|
|
791
791
|
const storedRunDirectory = typeof record.runDirectory === "string" && record.runDirectory.trim() !== ""
|
|
792
792
|
? record.runDirectory
|
|
793
793
|
: run.runDirectory;
|
|
794
|
-
rewriteAdmittedRoleRunPage(record,
|
|
795
|
-
oldRunDirectory: storedRunDirectory,
|
|
796
|
-
newRunDirectory: run.runDirectory,
|
|
797
|
-
}]);
|
|
794
|
+
rewriteAdmittedRoleRunPage(record, storedRunDirectory, run.runDirectory);
|
|
798
795
|
if (typeof record.instruction === "string") {
|
|
799
796
|
instruction = record.instruction;
|
|
800
797
|
}
|
|
@@ -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.
|
|
@@ -17,19 +17,8 @@ export const ADMITTED_PAGE_PATH_FIELDS = [
|
|
|
17
17
|
"mergerInputPath",
|
|
18
18
|
"sourceRunPath",
|
|
19
19
|
];
|
|
20
|
-
export const INVOCATION_PAGE_PATH_FIELDS = [
|
|
21
|
-
"runDirectory",
|
|
22
|
-
"sessionDirectory",
|
|
23
|
-
"sessionFile",
|
|
24
|
-
];
|
|
25
|
-
export const RUN_STATE_PAGE_PATH_FIELDS = [
|
|
26
|
-
"runDirectory",
|
|
27
|
-
"admittedRequestPath", // pre-#1161 pages only
|
|
28
|
-
"sessionDirectory",
|
|
29
|
-
"sessionFile",
|
|
30
|
-
];
|
|
31
20
|
/** Typed principal session coordinates rewritten when the owning run leaf moves. */
|
|
32
|
-
|
|
21
|
+
const PRINCIPAL_SESSION_PATH_FIELDS = [
|
|
33
22
|
"sessionDirectory",
|
|
34
23
|
"sessionFile",
|
|
35
24
|
];
|
|
@@ -47,38 +36,11 @@ export function rewriteRunDirectoryPathValue(value, oldRunDirectory, newRunDirec
|
|
|
47
36
|
}
|
|
48
37
|
return value;
|
|
49
38
|
}
|
|
50
|
-
/**
|
|
51
|
-
|
|
52
|
-
* nested run path is not partially claimed by a shorter sibling prefix.
|
|
53
|
-
*/
|
|
54
|
-
export function rewriteRunDirectoryPathValueAgainstRewrites(value, rewrites) {
|
|
55
|
-
if (typeof value !== "string" || rewrites.length === 0)
|
|
56
|
-
return value;
|
|
57
|
-
let best;
|
|
58
|
-
for (const rewrite of rewrites) {
|
|
59
|
-
if (value === rewrite.oldRunDirectory ||
|
|
60
|
-
value.startsWith(`${rewrite.oldRunDirectory}${sep}`)) {
|
|
61
|
-
if (best === undefined ||
|
|
62
|
-
rewrite.oldRunDirectory.length > best.oldRunDirectory.length) {
|
|
63
|
-
best = rewrite;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
if (best === undefined)
|
|
68
|
-
return value;
|
|
69
|
-
return rewriteRunDirectoryPathValue(value, best.oldRunDirectory, best.newRunDirectory);
|
|
70
|
-
}
|
|
71
|
-
/** In-place rewrite of selected fields on one record (single pair). */
|
|
72
|
-
export function rewriteRunDirectoryPathFields(record, fields, oldRunDirectory, newRunDirectory) {
|
|
73
|
-
rewriteRunDirectoryPathFieldsAgainstRewrites(record, fields, [
|
|
74
|
-
{ oldRunDirectory, newRunDirectory },
|
|
75
|
-
]);
|
|
76
|
-
}
|
|
77
|
-
/** In-place rewrite of selected fields against a rewrite set. */
|
|
78
|
-
export function rewriteRunDirectoryPathFieldsAgainstRewrites(record, fields, rewrites) {
|
|
39
|
+
/** In-place rewrite of selected fields on one record. */
|
|
40
|
+
function rewriteRunDirectoryPathFields(record, fields, oldRunDirectory, newRunDirectory) {
|
|
79
41
|
for (const field of fields) {
|
|
80
42
|
if (field in record) {
|
|
81
|
-
record[field] =
|
|
43
|
+
record[field] = rewriteRunDirectoryPathValue(record[field], oldRunDirectory, newRunDirectory);
|
|
82
44
|
}
|
|
83
45
|
}
|
|
84
46
|
}
|
|
@@ -102,27 +64,24 @@ export function projectTurnRequestLiveRunDirectory(request, newRunDirectory, aut
|
|
|
102
64
|
request.principal = sealed;
|
|
103
65
|
}
|
|
104
66
|
/** Typed notary/source-run locator: only runDirectory is a path. */
|
|
105
|
-
export function rewriteSourceRunLocator(value,
|
|
67
|
+
export function rewriteSourceRunLocator(value, oldRunDirectory, newRunDirectory) {
|
|
106
68
|
if (!isRecord(value))
|
|
107
69
|
return;
|
|
108
|
-
|
|
70
|
+
rewriteRunDirectoryPathFields(value, SOURCE_RUN_LOCATOR_FIELDS, oldRunDirectory, newRunDirectory);
|
|
109
71
|
}
|
|
110
72
|
/** Same-ticket summons materials: typed source-run; caller attach paths stay as-is (#1165). */
|
|
111
|
-
|
|
73
|
+
function rewriteSummonsMaterials(value, oldRunDirectory, newRunDirectory) {
|
|
112
74
|
if (!isRecord(value))
|
|
113
75
|
return;
|
|
114
|
-
|
|
115
|
-
rewriteSourceRunLocator(value.sourceRun,
|
|
76
|
+
rewriteRunDirectoryPathFields(value, SUMMONS_PATH_FIELDS, oldRunDirectory, newRunDirectory);
|
|
77
|
+
rewriteSourceRunLocator(value.sourceRun, oldRunDirectory, newRunDirectory);
|
|
116
78
|
// #1165: summons.attachmentPaths are caller paths — do not rewrite.
|
|
117
79
|
}
|
|
118
80
|
/** Project one admitted page in memory after its containing run moved. */
|
|
119
|
-
export function rewriteAdmittedRoleRunPage(page,
|
|
120
|
-
|
|
121
|
-
rewriteSourceRunLocator(page.sourceRun,
|
|
81
|
+
export function rewriteAdmittedRoleRunPage(page, oldRunDirectory, newRunDirectory) {
|
|
82
|
+
rewriteRunDirectoryPathFields(page, ADMITTED_PAGE_PATH_FIELDS, oldRunDirectory, newRunDirectory);
|
|
83
|
+
rewriteSourceRunLocator(page.sourceRun, oldRunDirectory, newRunDirectory);
|
|
122
84
|
// #1165: admitted attachments are caller paths outside the run directory — do not rewrite.
|
|
123
|
-
if (isRecord(page.principal)) {
|
|
124
|
-
rewriteRunDirectoryPathFieldsAgainstRewrites(page.principal, PRINCIPAL_SESSION_PATH_FIELDS, rewrites);
|
|
125
|
-
}
|
|
126
85
|
}
|
|
127
86
|
/**
|
|
128
87
|
* #1183: current.json location fields follow the directory being rendered.
|
|
@@ -136,14 +95,11 @@ export function projectRenderedPagePaths(page, actualRunDirectory) {
|
|
|
136
95
|
if (stored === undefined || stored === actualRunDirectory)
|
|
137
96
|
return page;
|
|
138
97
|
const projected = structuredClone(page);
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
// Admitted field set is the location-field superset of invocation; runState adds
|
|
143
|
-
// principal (covered) and optional currentCourt summons under this run.
|
|
144
|
-
rewriteAdmittedRoleRunPage(projected, rewrites);
|
|
98
|
+
// Admitted field set is the location-field superset of invocation and runState;
|
|
99
|
+
// runState adds optional currentCourt summons under this run.
|
|
100
|
+
rewriteAdmittedRoleRunPage(projected, stored, actualRunDirectory);
|
|
145
101
|
if (isRecord(projected.currentCourt)) {
|
|
146
|
-
rewriteSummonsMaterials(projected.currentCourt.summons,
|
|
102
|
+
rewriteSummonsMaterials(projected.currentCourt.summons, stored, actualRunDirectory);
|
|
147
103
|
}
|
|
148
104
|
return projected;
|
|
149
105
|
}
|
|
@@ -1,27 +1,14 @@
|
|
|
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
|
import { activationBookDirectory, physicalPathIdentity } from "./activation-ledger-topology.js";
|
|
13
|
-
import { AUDITOR_PARENT_ATTEMPT_BINDING_ENTRY_TYPE } from "./compliance-transport.js";
|
|
14
7
|
import { readRoleRunIdentity } from "./public-cli/run-lifecycle.js";
|
|
15
|
-
import { roleRunPlacement
|
|
16
|
-
import {
|
|
17
|
-
import { readPageSync, updateSectionSync } from "./run-dossier.js";
|
|
18
|
-
import { isEnoent, isRecord } from "./unknown-value.js";
|
|
8
|
+
import { roleRunPlacement } from "./role-run-placement.js";
|
|
9
|
+
import { rewriteRunDirectoryPathValue } from "./role-run-path-rewrite.js";
|
|
19
10
|
// Re-export the pure path API so existing import sites stay on this module path.
|
|
20
|
-
export {
|
|
21
|
-
const OFFICER_POINTER_FIELDS = ["sessionFile", "runDirectory"];
|
|
22
|
-
const SITIAN_RECORD_FIELDS = ["sessionParent"];
|
|
23
|
-
const SESSION_HEADER_FIELDS = ["parentSession"];
|
|
24
|
-
const BINDING_PARENT_FIELDS = ["sessionFile"];
|
|
11
|
+
export { projectTurnRequestLiveRunDirectory, rewriteAdmittedRoleRunPage, rewritePrincipalSessionPaths, rewriteRunDirectoryPathValue, } from "./role-run-path-rewrite.js";
|
|
25
12
|
/** Match physical aliases or a normal unbound→ticket bind, never historical migration layouts. */
|
|
26
13
|
export async function retainedRunPathsMatch(recordedPath, currentPath, currentRunDirectory) {
|
|
27
14
|
if (recordedPath === currentPath)
|
|
@@ -57,256 +44,3 @@ export async function retainedRunPathsMatch(recordedPath, currentPath, currentRu
|
|
|
57
44
|
}
|
|
58
45
|
return false;
|
|
59
46
|
}
|
|
60
|
-
function collectRewrites(input) {
|
|
61
|
-
const own = {
|
|
62
|
-
oldRunDirectory: input.oldRunDirectory,
|
|
63
|
-
newRunDirectory: input.newRunDirectory,
|
|
64
|
-
};
|
|
65
|
-
if (input.crossRunRewrites === undefined ||
|
|
66
|
-
input.crossRunRewrites.length === 0) {
|
|
67
|
-
return [own];
|
|
68
|
-
}
|
|
69
|
-
// Own pair first; duplicates of the same old path keep the first (own) target.
|
|
70
|
-
const seen = new Set([own.oldRunDirectory]);
|
|
71
|
-
const out = [own];
|
|
72
|
-
for (const rewrite of input.crossRunRewrites) {
|
|
73
|
-
if (seen.has(rewrite.oldRunDirectory))
|
|
74
|
-
continue;
|
|
75
|
-
seen.add(rewrite.oldRunDirectory);
|
|
76
|
-
out.push(rewrite);
|
|
77
|
-
}
|
|
78
|
-
return out;
|
|
79
|
-
}
|
|
80
|
-
/** Pre-#1161 `session/auditor-roles/<officer>.pointer.json` (migrator input only). */
|
|
81
|
-
async function rewriteLegacyOfficerPointerFile(path, rewrites) {
|
|
82
|
-
const page = JSON.parse(await readFile(path, "utf8"));
|
|
83
|
-
if (!isRecord(page) || page.kind !== "direct-officer-run-pointer")
|
|
84
|
-
return;
|
|
85
|
-
const before = JSON.stringify(page);
|
|
86
|
-
rewriteRunDirectoryPathFieldsAgainstRewrites(page, OFFICER_POINTER_FIELDS, rewrites);
|
|
87
|
-
if (JSON.stringify(page) !== before)
|
|
88
|
-
await writeFile(path, `${JSON.stringify(page)}\n`, "utf8");
|
|
89
|
-
}
|
|
90
|
-
async function rewriteSitianRecordsJsonl(path, rewrites) {
|
|
91
|
-
let raw;
|
|
92
|
-
try {
|
|
93
|
-
raw = await readFile(path, "utf8");
|
|
94
|
-
}
|
|
95
|
-
catch (error) {
|
|
96
|
-
if (isEnoent(error))
|
|
97
|
-
return;
|
|
98
|
-
throw error;
|
|
99
|
-
}
|
|
100
|
-
if (raw.length === 0)
|
|
101
|
-
return;
|
|
102
|
-
const endsWithNewline = raw.endsWith("\n");
|
|
103
|
-
const lines = raw.split("\n");
|
|
104
|
-
// split keeps a trailing empty slot when file ends with \n — preserve it.
|
|
105
|
-
let changed = false;
|
|
106
|
-
const out = [];
|
|
107
|
-
for (let i = 0; i < lines.length; i += 1) {
|
|
108
|
-
const line = lines[i];
|
|
109
|
-
if (line === "" && i === lines.length - 1 && endsWithNewline) {
|
|
110
|
-
out.push("");
|
|
111
|
-
continue;
|
|
112
|
-
}
|
|
113
|
-
if (line.trim() === "") {
|
|
114
|
-
out.push(line);
|
|
115
|
-
continue;
|
|
116
|
-
}
|
|
117
|
-
let parsed;
|
|
118
|
-
try {
|
|
119
|
-
parsed = JSON.parse(line);
|
|
120
|
-
}
|
|
121
|
-
catch {
|
|
122
|
-
out.push(line);
|
|
123
|
-
continue;
|
|
124
|
-
}
|
|
125
|
-
if (!isRecord(parsed)) {
|
|
126
|
-
out.push(line);
|
|
127
|
-
continue;
|
|
128
|
-
}
|
|
129
|
-
if (!("sessionParent" in parsed)) {
|
|
130
|
-
out.push(line);
|
|
131
|
-
continue;
|
|
132
|
-
}
|
|
133
|
-
const before = parsed.sessionParent;
|
|
134
|
-
rewriteRunDirectoryPathFieldsAgainstRewrites(parsed, SITIAN_RECORD_FIELDS, rewrites);
|
|
135
|
-
if (parsed.sessionParent !== before)
|
|
136
|
-
changed = true;
|
|
137
|
-
out.push(JSON.stringify(parsed));
|
|
138
|
-
}
|
|
139
|
-
if (!changed)
|
|
140
|
-
return;
|
|
141
|
-
const body = out.join("\n");
|
|
142
|
-
await writeFile(path, endsWithNewline && !body.endsWith("\n") ? `${body}\n` : body, "utf8");
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Session transcript typed locators only: header.parentSession and
|
|
146
|
-
* ak_auditor_parent_attempt_binding data.parent.sessionFile. Never message text.
|
|
147
|
-
*/
|
|
148
|
-
async function rewriteSessionTranscriptBindings(path, rewrites) {
|
|
149
|
-
let raw;
|
|
150
|
-
try {
|
|
151
|
-
raw = await readFile(path, "utf8");
|
|
152
|
-
}
|
|
153
|
-
catch (error) {
|
|
154
|
-
if (isEnoent(error))
|
|
155
|
-
return;
|
|
156
|
-
throw error;
|
|
157
|
-
}
|
|
158
|
-
if (raw.length === 0)
|
|
159
|
-
return;
|
|
160
|
-
const endsWithNewline = raw.endsWith("\n");
|
|
161
|
-
const lines = raw.split("\n");
|
|
162
|
-
let changed = false;
|
|
163
|
-
const out = [];
|
|
164
|
-
for (let i = 0; i < lines.length; i += 1) {
|
|
165
|
-
const line = lines[i];
|
|
166
|
-
if (line === "" && i === lines.length - 1 && endsWithNewline) {
|
|
167
|
-
out.push("");
|
|
168
|
-
continue;
|
|
169
|
-
}
|
|
170
|
-
if (line.trim() === "") {
|
|
171
|
-
out.push(line);
|
|
172
|
-
continue;
|
|
173
|
-
}
|
|
174
|
-
let parsed;
|
|
175
|
-
try {
|
|
176
|
-
parsed = JSON.parse(line);
|
|
177
|
-
}
|
|
178
|
-
catch {
|
|
179
|
-
out.push(line);
|
|
180
|
-
continue;
|
|
181
|
-
}
|
|
182
|
-
if (!isRecord(parsed)) {
|
|
183
|
-
out.push(line);
|
|
184
|
-
continue;
|
|
185
|
-
}
|
|
186
|
-
let lineChanged = false;
|
|
187
|
-
if (parsed.type === "session" && "parentSession" in parsed) {
|
|
188
|
-
const before = parsed.parentSession;
|
|
189
|
-
rewriteRunDirectoryPathFieldsAgainstRewrites(parsed, SESSION_HEADER_FIELDS, rewrites);
|
|
190
|
-
if (parsed.parentSession !== before)
|
|
191
|
-
lineChanged = true;
|
|
192
|
-
}
|
|
193
|
-
else if (parsed.type === "custom" &&
|
|
194
|
-
parsed.customType === AUDITOR_PARENT_ATTEMPT_BINDING_ENTRY_TYPE &&
|
|
195
|
-
isRecord(parsed.data) &&
|
|
196
|
-
isRecord(parsed.data.parent)) {
|
|
197
|
-
const parent = parsed.data.parent;
|
|
198
|
-
const before = parent.sessionFile;
|
|
199
|
-
rewriteRunDirectoryPathFieldsAgainstRewrites(parent, BINDING_PARENT_FIELDS, rewrites);
|
|
200
|
-
if (parent.sessionFile !== before)
|
|
201
|
-
lineChanged = true;
|
|
202
|
-
}
|
|
203
|
-
if (lineChanged)
|
|
204
|
-
changed = true;
|
|
205
|
-
out.push(lineChanged ? JSON.stringify(parsed) : line);
|
|
206
|
-
}
|
|
207
|
-
if (!changed)
|
|
208
|
-
return;
|
|
209
|
-
const body = out.join("\n");
|
|
210
|
-
await writeFile(path, endsWithNewline && !body.endsWith("\n") ? `${body}\n` : body, "utf8");
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* Package-owned nested seams under session/ only:
|
|
214
|
-
* sitian records.jsonl,
|
|
215
|
-
* session transcript typed parent bindings. Never walks caller file paths.
|
|
216
|
-
*/
|
|
217
|
-
async function rewriteNestedMachinePathPages(pagesDirectory, rewrites) {
|
|
218
|
-
const sessionRoot = sessionDirectoryOf(pagesDirectory);
|
|
219
|
-
async function walk(directory) {
|
|
220
|
-
let entries;
|
|
221
|
-
try {
|
|
222
|
-
entries = await readdir(directory, { withFileTypes: true });
|
|
223
|
-
}
|
|
224
|
-
catch (error) {
|
|
225
|
-
if (isEnoent(error))
|
|
226
|
-
return;
|
|
227
|
-
throw error;
|
|
228
|
-
}
|
|
229
|
-
for (const entry of entries) {
|
|
230
|
-
const path = join(directory, entry.name);
|
|
231
|
-
if (entry.isDirectory()) {
|
|
232
|
-
await walk(path);
|
|
233
|
-
continue;
|
|
234
|
-
}
|
|
235
|
-
if (!entry.isFile())
|
|
236
|
-
continue;
|
|
237
|
-
if (entry.name.endsWith(".pointer.json")) {
|
|
238
|
-
await rewriteLegacyOfficerPointerFile(path, rewrites);
|
|
239
|
-
}
|
|
240
|
-
else if (entry.name === "records.jsonl") {
|
|
241
|
-
await rewriteSitianRecordsJsonl(path, rewrites);
|
|
242
|
-
}
|
|
243
|
-
else if (entry.name.endsWith(".jsonl")) {
|
|
244
|
-
await rewriteSessionTranscriptBindings(path, rewrites);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
await walk(sessionRoot);
|
|
249
|
-
}
|
|
250
|
-
/**
|
|
251
|
-
* Rewrite the admitted / invocation / runState fact rows (typed run placement
|
|
252
|
-
* paths only; caller --attach / --request-manifest paths stay as-is, #1165),
|
|
253
|
-
* then nested package-owned session seams. Callers may rewrite before or after
|
|
254
|
-
* the filesystem move/copy: `pagesDirectory` is where the pages currently live
|
|
255
|
-
* on disk; path strings that still name `oldRunDirectory` become
|
|
256
|
-
* `newRunDirectory`. `crossRunRewrites` covers officer/parent pointers that
|
|
257
|
-
* landed under a different final placement.
|
|
258
|
-
*/
|
|
259
|
-
export async function rewriteRoleRunDurablePages(input) {
|
|
260
|
-
const { pagesDirectory } = input;
|
|
261
|
-
const rewrites = collectRewrites(input);
|
|
262
|
-
// One rewriter per page kind; each keeps its own field list.
|
|
263
|
-
const pageRewriters = {
|
|
264
|
-
admitted: (page) => rewriteAdmittedRoleRunPage(page, rewrites),
|
|
265
|
-
invocation: (page) => rewriteRunDirectoryPathFieldsAgainstRewrites(page, INVOCATION_PAGE_PATH_FIELDS, rewrites),
|
|
266
|
-
runState: (page) => {
|
|
267
|
-
rewriteRunDirectoryPathFieldsAgainstRewrites(page, RUN_STATE_PAGE_PATH_FIELDS, rewrites);
|
|
268
|
-
if (isRecord(page.principal)) {
|
|
269
|
-
rewriteRunDirectoryPathFieldsAgainstRewrites(page.principal, PRINCIPAL_SESSION_PATH_FIELDS, rewrites);
|
|
270
|
-
}
|
|
271
|
-
// Open court summons: source-run locators only; caller attach paths stay (#1165).
|
|
272
|
-
if (isRecord(page.currentCourt)) {
|
|
273
|
-
rewriteSummonsMaterials(page.currentCourt.summons, rewrites);
|
|
274
|
-
}
|
|
275
|
-
},
|
|
276
|
-
};
|
|
277
|
-
// A page is rewritten only when its fact row exists — never gate on the rendering.
|
|
278
|
-
for (const [section, rewrite] of Object.entries(pageRewriters)) {
|
|
279
|
-
if (readPageSync(pagesDirectory, section) === undefined)
|
|
280
|
-
continue;
|
|
281
|
-
updateSectionSync(pagesDirectory, section, (current) => {
|
|
282
|
-
const page = structuredClone(current);
|
|
283
|
-
rewrite(page);
|
|
284
|
-
return JSON.stringify(page) === JSON.stringify(current) ? undefined : page;
|
|
285
|
-
});
|
|
286
|
-
}
|
|
287
|
-
// Runs from before #1161 (the one-shot book-topology migrator's input) keep these
|
|
288
|
-
// as separate page files; the same rewriters apply. Nothing live writes them.
|
|
289
|
-
for (const [file, rewrite] of [
|
|
290
|
-
["admitted-request.json", pageRewriters.admitted],
|
|
291
|
-
["invocation.json", pageRewriters.invocation],
|
|
292
|
-
["run-state.json", pageRewriters.runState],
|
|
293
|
-
]) {
|
|
294
|
-
const path = join(pagesDirectory, file);
|
|
295
|
-
let raw;
|
|
296
|
-
try {
|
|
297
|
-
raw = await readFile(path, "utf8");
|
|
298
|
-
}
|
|
299
|
-
catch (error) {
|
|
300
|
-
if (isEnoent(error))
|
|
301
|
-
continue;
|
|
302
|
-
throw error;
|
|
303
|
-
}
|
|
304
|
-
const page = JSON.parse(raw);
|
|
305
|
-
const before = JSON.stringify(page);
|
|
306
|
-
rewrite(page);
|
|
307
|
-
if (JSON.stringify(page) !== before) {
|
|
308
|
-
await writeFile(path, `${JSON.stringify(page, null, 2)}\n`, "utf8");
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
await rewriteNestedMachinePathPages(pagesDirectory, rewrites);
|
|
312
|
-
}
|
|
@@ -62,25 +62,13 @@ async function readJsonObject(path) {
|
|
|
62
62
|
throw error;
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
|
-
const LEGACY_BOARD_PAGE = {
|
|
66
|
-
admitted: "admitted-request.json",
|
|
67
|
-
invocation: "invocation.json"
|
|
68
|
-
};
|
|
69
65
|
function readBoardPageTicketNumberFromRows(runDirectory, section) {
|
|
70
66
|
const fromRows = readPageSync(runDirectory, section);
|
|
71
67
|
return fromRows === void 0 ? void 0 : ticketFromRecord(fromRows);
|
|
72
68
|
}
|
|
73
|
-
async function readBoardPageTicketNumberFromLegacy(runDirectory, section) {
|
|
74
|
-
const record = await readJsonObject(join(runDirectory, LEGACY_BOARD_PAGE[section]));
|
|
75
|
-
if (record === void 0) return void 0;
|
|
76
|
-
return ticketFromRecord(record);
|
|
77
|
-
}
|
|
78
69
|
async function readBoardTicketNumber(runDirectory) {
|
|
79
70
|
return readBoardPageTicketNumberFromRows(runDirectory, "admitted") ?? readBoardPageTicketNumberFromRows(runDirectory, "invocation");
|
|
80
71
|
}
|
|
81
|
-
async function readMigrationBoardTicketNumber(runDirectory) {
|
|
82
|
-
return await readBoardTicketNumber(runDirectory) ?? await readBoardPageTicketNumberFromLegacy(runDirectory, "admitted") ?? await readBoardPageTicketNumberFromLegacy(runDirectory, "invocation");
|
|
83
|
-
}
|
|
84
72
|
async function readMigrationDerivedTicketNumber(runDirectory) {
|
|
85
73
|
const record = await readJsonObject(
|
|
86
74
|
join(runDirectory, MIGRATION_TICKET_DERIVATION_PAGE)
|
|
@@ -93,15 +81,12 @@ async function readRunTicketNumber(runDirectory) {
|
|
|
93
81
|
return await readBoardTicketNumber(runDirectory) ?? await readMigrationDerivedTicketNumber(runDirectory);
|
|
94
82
|
}
|
|
95
83
|
export {
|
|
96
|
-
MIGRATION_TICKET_DERIVATION_PAGE,
|
|
97
84
|
isPositiveTicketNumber,
|
|
98
85
|
isSafePositiveTicketNumber,
|
|
99
86
|
isTicketNumberString,
|
|
100
87
|
parseTicketNumber,
|
|
101
88
|
readBoardTicketNumber,
|
|
102
89
|
readDeclaredTicketNumber,
|
|
103
|
-
readMigrationBoardTicketNumber,
|
|
104
|
-
readMigrationDerivedTicketNumber,
|
|
105
90
|
readRunTicketNumber,
|
|
106
91
|
requireSafePositiveTicketNumber,
|
|
107
92
|
sitianSubjectTicketNumber,
|
|
@@ -56,27 +56,3 @@ export function projectTicketProvenanceSessions(value) {
|
|
|
56
56
|
}
|
|
57
57
|
return sessions;
|
|
58
58
|
}
|
|
59
|
-
/** 读回册子头(文件第一行)。形状不成立即 undefined——按无册处理,不猜。 */
|
|
60
|
-
export function projectTicketProvenanceHeader(value) {
|
|
61
|
-
if (!isRecord(value))
|
|
62
|
-
return undefined;
|
|
63
|
-
const ticket = value.ticket === null ? null : positiveInteger(value.ticket);
|
|
64
|
-
if (ticket === undefined)
|
|
65
|
-
return undefined;
|
|
66
|
-
if (typeof value.repo !== "string")
|
|
67
|
-
return undefined;
|
|
68
|
-
if (typeof value.createdAt !== "string" || typeof value.updatedAt !== "string") {
|
|
69
|
-
return undefined;
|
|
70
|
-
}
|
|
71
|
-
// Malformed sessions stay unusable — do not wash into lawful empty (失败诚实).
|
|
72
|
-
const sessions = projectTicketProvenanceSessions(value.sessions);
|
|
73
|
-
if (sessions === undefined)
|
|
74
|
-
return undefined;
|
|
75
|
-
return {
|
|
76
|
-
repo: value.repo,
|
|
77
|
-
ticket,
|
|
78
|
-
createdAt: value.createdAt,
|
|
79
|
-
updatedAt: value.updatedAt,
|
|
80
|
-
sessions,
|
|
81
|
-
};
|
|
82
|
-
}
|
|
@@ -92,7 +92,7 @@ export async function rehomeUnboundTicketProvenance(runDirectory, ticketNumber,
|
|
|
92
92
|
const ticketInput = ticketProvenanceRecordInput(ticketNumber, cwd, home);
|
|
93
93
|
// Live staging: ticket-provenance rows in the run's history.jsonl. Append-only
|
|
94
94
|
// history keeps the staging rows; the ticket-root diary is the home.
|
|
95
|
-
// Old run/records.jsonl is not a runtime input (#1161)
|
|
95
|
+
// Old run/records.jsonl is not a runtime input (#1161).
|
|
96
96
|
let history;
|
|
97
97
|
try {
|
|
98
98
|
history = await readFile(join(runDirectory, RUN_HISTORY_FILE), "utf8");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@akagilnc/pi-workflow-roles",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6131",
|
|
4
4
|
"description": "Soul-bound workflow roles for Pi",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -48,8 +48,7 @@
|
|
|
48
48
|
"test:fast": "pnpm test",
|
|
49
49
|
"test:integration": "vitest run --project integration",
|
|
50
50
|
"test:all": "vitest run",
|
|
51
|
-
"typecheck": "tsc --noEmit"
|
|
52
|
-
"migrate:book-topology": "node dist/migrate-book-topology.js"
|
|
51
|
+
"typecheck": "tsc --noEmit"
|
|
53
52
|
},
|
|
54
53
|
"pi": {
|
|
55
54
|
"extensions": []
|
|
@@ -139,35 +139,6 @@ export async function buildHeadlessProductionHost(
|
|
|
139
139
|
);
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
-
/**
|
|
143
|
-
* Published one-shot book-topology migration CLI (#852).
|
|
144
|
-
* Node-executable ESM bundle — consumers must not need dev-only tsx.
|
|
145
|
-
* createRequire banner lets transitive CJS deps reach node builtins.
|
|
146
|
-
*/
|
|
147
|
-
export async function buildMigrateBookTopology(
|
|
148
|
-
outfile = "dist/migrate-book-topology.js",
|
|
149
|
-
) {
|
|
150
|
-
await mkdir(dirname(outfile), { recursive: true });
|
|
151
|
-
await build({
|
|
152
|
-
entryPoints: ["scripts/migrate-book-topology.ts"],
|
|
153
|
-
outfile,
|
|
154
|
-
format: "esm",
|
|
155
|
-
platform: "node",
|
|
156
|
-
target: "node20",
|
|
157
|
-
bundle: true,
|
|
158
|
-
banner: {
|
|
159
|
-
js: [
|
|
160
|
-
"#!/usr/bin/env node",
|
|
161
|
-
"import { createRequire as __akCreateRequire } from 'node:module';",
|
|
162
|
-
"const require = __akCreateRequire(import.meta.url);",
|
|
163
|
-
"",
|
|
164
|
-
].join("\n"),
|
|
165
|
-
},
|
|
166
|
-
logLevel: "silent",
|
|
167
|
-
});
|
|
168
|
-
await chmod(outfile, 0o755);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
142
|
export async function buildPackageArtifacts() {
|
|
172
143
|
await build({
|
|
173
144
|
entryPoints: entries.map((name) => `src/${name}.ts`),
|
|
@@ -194,7 +165,6 @@ export async function buildPackageArtifacts() {
|
|
|
194
165
|
await buildPublicAkRoleBin();
|
|
195
166
|
await buildAcpProductionHost();
|
|
196
167
|
await buildHeadlessProductionHost();
|
|
197
|
-
await buildMigrateBookTopology();
|
|
198
168
|
// Packaged handbook/playbook paths resolve via injected packageRoot (#962) —
|
|
199
169
|
// do not mirror resources/ into dist/resources (one authority, no parallel copy).
|
|
200
170
|
}
|
|
@@ -737,7 +737,8 @@ export async function relocateAdmittedRunToTicket(
|
|
|
737
737
|
|
|
738
738
|
rewriteAdmittedRoleRunPage(
|
|
739
739
|
admitted as unknown as Record<string, unknown>,
|
|
740
|
-
|
|
740
|
+
oldRunDirectory,
|
|
741
|
+
target.runDirectory,
|
|
741
742
|
);
|
|
742
743
|
(admitted as { principal: DurablePrincipal }).principal = principal;
|
|
743
744
|
|
|
@@ -178,7 +178,8 @@ export async function refreshAdmittedPlacementAfterHostTurn(
|
|
|
178
178
|
const principal = authority.seal(coords);
|
|
179
179
|
rewriteAdmittedRoleRunPage(
|
|
180
180
|
admitted as unknown as Record<string, unknown>,
|
|
181
|
-
|
|
181
|
+
oldRunDirectory,
|
|
182
|
+
found,
|
|
182
183
|
);
|
|
183
184
|
(admitted as { principal: typeof principal }).principal = principal;
|
|
184
185
|
heldLease?.relocate(found);
|
|
@@ -1114,10 +1114,7 @@ async function loadResumableRunRecord(
|
|
|
1114
1114
|
typeof record.runDirectory === "string" && record.runDirectory.trim() !== ""
|
|
1115
1115
|
? record.runDirectory
|
|
1116
1116
|
: run.runDirectory;
|
|
1117
|
-
rewriteAdmittedRoleRunPage(record,
|
|
1118
|
-
oldRunDirectory: storedRunDirectory,
|
|
1119
|
-
newRunDirectory: run.runDirectory,
|
|
1120
|
-
}]);
|
|
1117
|
+
rewriteAdmittedRoleRunPage(record, storedRunDirectory, run.runDirectory);
|
|
1121
1118
|
if (typeof record.instruction === "string") {
|
|
1122
1119
|
instruction = record.instruction;
|
|
1123
1120
|
}
|