@akagilnc/pi-workflow-roles 0.1.6126 → 0.1.6134
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
|
@@ -1,272 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* #865 T9: migrate retained runs into ticket-scoped or unbound placement.
|
|
3
|
-
* Inventory covers legacy flat `runs/`, existing `<ticket>/runs/`, and
|
|
4
|
-
* `unbound/runs/`. Attribution reuses the shared migrating-run helper;
|
|
5
|
-
* already-canonical ticket trees copy as-is. Unbound leaves that already
|
|
6
|
-
* hold a board typed ticketNumber place under that ticket (#863 stock).
|
|
7
|
-
*/
|
|
8
|
-
import { cp, mkdir, rename, readdir, stat, writeFile } from "node:fs/promises";
|
|
9
|
-
import { basename, dirname, join, relative, sep } from "node:path";
|
|
10
|
-
import { destinationRunDirectory, isTicketNumberString, listBackupRunLeaves, listMigrationBookKeys, resolveMigratingRunTicket, } from "./book-topology-migration-placement.js";
|
|
11
|
-
import { reconcileMigrationPartition, } from "./book-topology-migration.js";
|
|
12
|
-
import { listBookRunDirectories } from "./role-run-placement.js";
|
|
13
|
-
import { rewriteRoleRunDurablePages, } from "./role-run-relocation.js";
|
|
14
|
-
import { renderCurrentSync } from "./run-dossier.js";
|
|
15
|
-
import { MIGRATION_TICKET_DERIVATION_PAGE, readMigrationBoardTicketNumber, } from "./run-ticket-number.js";
|
|
16
|
-
import { isEnoent } from "./unknown-value.js";
|
|
17
|
-
const RUNS_PARTITION = "runs";
|
|
18
|
-
const RUN_LEAF = /^([A-Za-z0-9][A-Za-z0-9._-]*)@([A-Za-z][A-Za-z0-9_-]*)$/;
|
|
19
|
-
function parseRunLeaf(name) {
|
|
20
|
-
const match = RUN_LEAF.exec(name);
|
|
21
|
-
if (match === null)
|
|
22
|
-
return undefined;
|
|
23
|
-
return { runId: match[1], role: match[2] };
|
|
24
|
-
}
|
|
25
|
-
async function pathExists(path) {
|
|
26
|
-
try {
|
|
27
|
-
await stat(path);
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
-
catch (error) {
|
|
31
|
-
if (isEnoent(error))
|
|
32
|
-
return false;
|
|
33
|
-
throw error;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
async function writeDerivationPage(targetRunDirectory, derivation) {
|
|
37
|
-
const page = {
|
|
38
|
-
ticketNumber: derivation.ticketNumber,
|
|
39
|
-
derivation: "worktree-path-basename",
|
|
40
|
-
source: {
|
|
41
|
-
page: derivation.sourcePage,
|
|
42
|
-
field: "projectRoot",
|
|
43
|
-
path: derivation.projectRoot,
|
|
44
|
-
basename: basename(derivation.projectRoot),
|
|
45
|
-
},
|
|
46
|
-
};
|
|
47
|
-
await writeFile(join(targetRunDirectory, MIGRATION_TICKET_DERIVATION_PAGE), `${JSON.stringify(page, null, 2)}\n`, "utf8");
|
|
48
|
-
}
|
|
49
|
-
async function copyRunTree(source, target, isDirectory) {
|
|
50
|
-
await mkdir(dirname(target), { recursive: true });
|
|
51
|
-
if (isDirectory) {
|
|
52
|
-
await cp(source, target, { recursive: true, preserveTimestamps: true });
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
await cp(source, target, { preserveTimestamps: true });
|
|
56
|
-
}
|
|
57
|
-
async function planBookMoves(backupBooksDirectory, booksDirectory, bookKey) {
|
|
58
|
-
const backupBook = join(backupBooksDirectory, bookKey);
|
|
59
|
-
const claimed = new Map();
|
|
60
|
-
const planned = [];
|
|
61
|
-
for (const leaf of await listBackupRunLeaves(backupBook)) {
|
|
62
|
-
const sourceIdentity = relative(backupBooksDirectory, leaf.sourcePath)
|
|
63
|
-
.split(sep)
|
|
64
|
-
.join("/");
|
|
65
|
-
const parsed = leaf.isDirectory ? parseRunLeaf(leaf.leafName) : undefined;
|
|
66
|
-
let targetPath;
|
|
67
|
-
let disposition;
|
|
68
|
-
let historicalRunDirectory;
|
|
69
|
-
let derivation;
|
|
70
|
-
if (leaf.layout === "issues") {
|
|
71
|
-
// issues/<ticket>/runs/<leaf> → <ticket>/runs/<leaf>; conflict refuses below.
|
|
72
|
-
const parts = leaf.relativePath.replaceAll("\\", "/").split("/");
|
|
73
|
-
const ticketStr = parts[1];
|
|
74
|
-
if (ticketStr !== undefined && isTicketNumberString(ticketStr)) {
|
|
75
|
-
targetPath = join(booksDirectory, bookKey, ticketStr, "runs", leaf.leafName);
|
|
76
|
-
disposition = "placed";
|
|
77
|
-
historicalRunDirectory = join(booksDirectory, bookKey, "issues", ticketStr, "runs", leaf.leafName);
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
targetPath = join(booksDirectory, bookKey, "unbound", "runs", leaf.leafName);
|
|
81
|
-
disposition = "unbound";
|
|
82
|
-
historicalRunDirectory = join(booksDirectory, bookKey, leaf.relativePath);
|
|
83
|
-
}
|
|
84
|
-
derivation = undefined;
|
|
85
|
-
}
|
|
86
|
-
else if (leaf.layout === "unbound") {
|
|
87
|
-
// #863: board typed ticket on an unbound leaf → place under that ticket.
|
|
88
|
-
// No board ticket → stay unbound. Never invent from prose or derivation.
|
|
89
|
-
const boardTicket = leaf.isDirectory
|
|
90
|
-
? await readMigrationBoardTicketNumber(leaf.sourcePath)
|
|
91
|
-
: undefined;
|
|
92
|
-
if (parsed !== undefined && boardTicket !== undefined) {
|
|
93
|
-
targetPath = destinationRunDirectory(booksDirectory, bookKey, boardTicket, parsed.runId, parsed.role);
|
|
94
|
-
disposition = "placed";
|
|
95
|
-
historicalRunDirectory = join(booksDirectory, bookKey, "unbound", "runs", leaf.leafName);
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
targetPath = join(booksDirectory, bookKey, leaf.relativePath);
|
|
99
|
-
disposition = "unbound";
|
|
100
|
-
historicalRunDirectory = undefined;
|
|
101
|
-
}
|
|
102
|
-
derivation = undefined;
|
|
103
|
-
}
|
|
104
|
-
else if (leaf.layout !== "flat") {
|
|
105
|
-
// Already-canonical `<ticket>/runs/` — copy as-is.
|
|
106
|
-
targetPath = join(booksDirectory, bookKey, leaf.relativePath);
|
|
107
|
-
disposition = "placed";
|
|
108
|
-
historicalRunDirectory = undefined;
|
|
109
|
-
derivation = undefined;
|
|
110
|
-
}
|
|
111
|
-
else if (parsed === undefined) {
|
|
112
|
-
targetPath = join(booksDirectory, bookKey, "unbound", "runs", leaf.leafName);
|
|
113
|
-
disposition = "unbound";
|
|
114
|
-
historicalRunDirectory = join(booksDirectory, bookKey, "runs", leaf.leafName);
|
|
115
|
-
derivation = undefined;
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
const ticket = await resolveMigratingRunTicket(leaf.sourcePath);
|
|
119
|
-
targetPath = destinationRunDirectory(booksDirectory, bookKey, ticket.ticketNumber, parsed.runId, parsed.role);
|
|
120
|
-
disposition = ticket.ticketNumber === undefined ? "unbound" : "placed";
|
|
121
|
-
historicalRunDirectory = join(booksDirectory, bookKey, "runs", leaf.leafName);
|
|
122
|
-
derivation =
|
|
123
|
-
ticket.derivation?.method === "project-root-basename"
|
|
124
|
-
&& ticket.ticketNumber !== undefined
|
|
125
|
-
? {
|
|
126
|
-
ticketNumber: ticket.ticketNumber,
|
|
127
|
-
projectRoot: ticket.derivation.source,
|
|
128
|
-
sourcePage: ticket.derivation.sourcePage,
|
|
129
|
-
}
|
|
130
|
-
: undefined;
|
|
131
|
-
}
|
|
132
|
-
const prior = claimed.get(targetPath);
|
|
133
|
-
if (prior !== undefined) {
|
|
134
|
-
throw new Error(`book topology migration refuses to overwrite ${targetPath} (already claimed by ${prior}) with ${leaf.sourcePath}`);
|
|
135
|
-
}
|
|
136
|
-
claimed.set(targetPath, leaf.sourcePath);
|
|
137
|
-
planned.push({
|
|
138
|
-
sourcePath: leaf.sourcePath,
|
|
139
|
-
sourceIdentity,
|
|
140
|
-
isDirectory: leaf.isDirectory,
|
|
141
|
-
disposition,
|
|
142
|
-
targetPath,
|
|
143
|
-
historicalRunDirectory,
|
|
144
|
-
derivation,
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
return planned;
|
|
148
|
-
}
|
|
149
|
-
export const bookTopologyRunsMigrator = {
|
|
150
|
-
partition: RUNS_PARTITION,
|
|
151
|
-
async migrate(context) {
|
|
152
|
-
const outcomes = [];
|
|
153
|
-
const { backupBooksDirectory, booksDirectory } = context;
|
|
154
|
-
for (const bookKey of await listMigrationBookKeys(backupBooksDirectory)) {
|
|
155
|
-
const planned = await planBookMoves(backupBooksDirectory, booksDirectory, bookKey);
|
|
156
|
-
const crossRunRewrites = planned
|
|
157
|
-
.filter((move) => move.isDirectory && move.historicalRunDirectory !== undefined)
|
|
158
|
-
.map((move) => ({
|
|
159
|
-
oldRunDirectory: move.historicalRunDirectory,
|
|
160
|
-
newRunDirectory: move.targetPath,
|
|
161
|
-
}));
|
|
162
|
-
for (const move of planned) {
|
|
163
|
-
if (await pathExists(move.targetPath)) {
|
|
164
|
-
throw new Error(`book topology migration refuses to overwrite ${move.targetPath} with ${move.sourcePath}`);
|
|
165
|
-
}
|
|
166
|
-
await copyRunTree(move.sourcePath, move.targetPath, move.isDirectory);
|
|
167
|
-
if (move.isDirectory) {
|
|
168
|
-
await rewriteRoleRunDurablePages({
|
|
169
|
-
pagesDirectory: move.targetPath,
|
|
170
|
-
oldRunDirectory: move.historicalRunDirectory ?? move.targetPath,
|
|
171
|
-
newRunDirectory: move.targetPath,
|
|
172
|
-
crossRunRewrites,
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
if (move.isDirectory && move.derivation !== undefined) {
|
|
176
|
-
await writeDerivationPage(move.targetPath, move.derivation);
|
|
177
|
-
}
|
|
178
|
-
outcomes.push({
|
|
179
|
-
disposition: move.disposition,
|
|
180
|
-
source: move.sourceIdentity,
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
return reconcileMigrationPartition(RUNS_PARTITION, "entries", outcomes);
|
|
185
|
-
},
|
|
186
|
-
};
|
|
187
|
-
/**
|
|
188
|
-
* Live in-place repair for already-migrated trees (#863 stock): plan the full
|
|
189
|
-
* board-bound unbound→ticket batch first, refuse any overwrite before mutation,
|
|
190
|
-
* rewrite durable pages (including batch `crossRunRewrites`) while sources still
|
|
191
|
-
* sit at unbound, then rename. Parse/write failures therefore leave sources in
|
|
192
|
-
* place so a retry can finish the same closure; rename-only retries still find
|
|
193
|
-
* remaining unbound sources. Leaves without a board ticket stay unbound.
|
|
194
|
-
*/
|
|
195
|
-
export async function relocateBoardBoundUnboundRunsInBook(bookDirectory) {
|
|
196
|
-
const bookKey = basename(bookDirectory);
|
|
197
|
-
const booksDirectory = dirname(bookDirectory);
|
|
198
|
-
const unboundRuns = join(bookDirectory, "unbound", "runs");
|
|
199
|
-
let entries;
|
|
200
|
-
try {
|
|
201
|
-
entries = await readdir(unboundRuns, { withFileTypes: true });
|
|
202
|
-
}
|
|
203
|
-
catch (error) {
|
|
204
|
-
if (isEnoent(error))
|
|
205
|
-
return [];
|
|
206
|
-
throw error;
|
|
207
|
-
}
|
|
208
|
-
const planned = [];
|
|
209
|
-
for (const entry of entries) {
|
|
210
|
-
if (!entry.isDirectory())
|
|
211
|
-
continue;
|
|
212
|
-
const parsed = parseRunLeaf(entry.name);
|
|
213
|
-
if (parsed === undefined)
|
|
214
|
-
continue;
|
|
215
|
-
const sourcePath = join(unboundRuns, entry.name);
|
|
216
|
-
const boardTicket = await readMigrationBoardTicketNumber(sourcePath);
|
|
217
|
-
if (boardTicket === undefined)
|
|
218
|
-
continue;
|
|
219
|
-
const targetPath = destinationRunDirectory(booksDirectory, bookKey, boardTicket, parsed.runId, parsed.role);
|
|
220
|
-
planned.push({
|
|
221
|
-
sourcePath,
|
|
222
|
-
targetPath,
|
|
223
|
-
ticketNumber: boardTicket,
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
if (planned.length === 0)
|
|
227
|
-
return [];
|
|
228
|
-
for (const move of planned) {
|
|
229
|
-
if (await pathExists(move.targetPath)) {
|
|
230
|
-
throw new Error(`board-bound unbound relocate refuses to overwrite ${move.targetPath} with ${move.sourcePath}`);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
const crossRunRewrites = planned.map((move) => ({
|
|
234
|
-
oldRunDirectory: move.sourcePath,
|
|
235
|
-
newRunDirectory: move.targetPath,
|
|
236
|
-
}));
|
|
237
|
-
const relocatedBySource = new Map(planned.map((move) => [move.sourcePath, move]));
|
|
238
|
-
// Rewrite before any rename so durable-page failures remain retryable from
|
|
239
|
-
// the same unbound sources (failure-honesty: no relocatedCount=0 whitewash).
|
|
240
|
-
for (const runDir of await listBookRunDirectories(bookDirectory)) {
|
|
241
|
-
const move = relocatedBySource.get(runDir);
|
|
242
|
-
await rewriteRoleRunDurablePages({
|
|
243
|
-
pagesDirectory: runDir,
|
|
244
|
-
oldRunDirectory: move?.sourcePath ?? runDir,
|
|
245
|
-
newRunDirectory: move?.targetPath ?? runDir,
|
|
246
|
-
crossRunRewrites,
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
for (const move of planned) {
|
|
250
|
-
await mkdir(dirname(move.targetPath), { recursive: true });
|
|
251
|
-
await rename(move.sourcePath, move.targetPath);
|
|
252
|
-
// Same live relocate seam: derived host.original follows the new run directory.
|
|
253
|
-
renderCurrentSync(move.targetPath);
|
|
254
|
-
}
|
|
255
|
-
return planned.map((move) => ({
|
|
256
|
-
from: move.sourcePath,
|
|
257
|
-
to: move.targetPath,
|
|
258
|
-
ticketNumber: move.ticketNumber,
|
|
259
|
-
}));
|
|
260
|
-
}
|
|
261
|
-
/**
|
|
262
|
-
* Walk every book under `booksDirectory` and relocate board-bound unbound
|
|
263
|
-
* runs in place without the whole-books topology migration's in-flight gate.
|
|
264
|
-
*/
|
|
265
|
-
export async function relocateBoardBoundUnboundRunsInBooks(booksDirectory) {
|
|
266
|
-
const relocated = [];
|
|
267
|
-
for (const bookKey of await listMigrationBookKeys(booksDirectory)) {
|
|
268
|
-
const batch = await relocateBoardBoundUnboundRunsInBook(join(booksDirectory, bookKey));
|
|
269
|
-
relocated.push(...batch);
|
|
270
|
-
}
|
|
271
|
-
return relocated;
|
|
272
|
-
}
|