@akagilnc/pi-workflow-roles 0.1.5683 → 0.1.5698

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.
@@ -700,6 +700,121 @@ var init_activation_ledger_topology = __esm({
700
700
  }
701
701
  });
702
702
 
703
+ // src/role-run-path-rewrite.ts
704
+ import { sep as sep2 } from "node:path";
705
+ function rewriteRunDirectoryPathValue(value, oldRunDirectory, newRunDirectory) {
706
+ if (typeof value !== "string") return value;
707
+ if (value === oldRunDirectory) return newRunDirectory;
708
+ const prefix = `${oldRunDirectory}${sep2}`;
709
+ if (value.startsWith(prefix)) {
710
+ return `${newRunDirectory}${value.slice(oldRunDirectory.length)}`;
711
+ }
712
+ return value;
713
+ }
714
+ function rewriteRunDirectoryPathValueAgainstRewrites(value, rewrites) {
715
+ if (typeof value !== "string" || rewrites.length === 0) return value;
716
+ let best;
717
+ for (const rewrite of rewrites) {
718
+ if (value === rewrite.oldRunDirectory || value.startsWith(`${rewrite.oldRunDirectory}${sep2}`)) {
719
+ if (best === void 0 || rewrite.oldRunDirectory.length > best.oldRunDirectory.length) {
720
+ best = rewrite;
721
+ }
722
+ }
723
+ }
724
+ if (best === void 0) return value;
725
+ return rewriteRunDirectoryPathValue(
726
+ value,
727
+ best.oldRunDirectory,
728
+ best.newRunDirectory
729
+ );
730
+ }
731
+ function rewriteRunDirectoryPathFieldsAgainstRewrites(record, fields, rewrites) {
732
+ for (const field of fields) {
733
+ if (field in record) {
734
+ record[field] = rewriteRunDirectoryPathValueAgainstRewrites(
735
+ record[field],
736
+ rewrites
737
+ );
738
+ }
739
+ }
740
+ }
741
+ function rewriteSourceRunLocator(value, rewrites) {
742
+ if (!isRecord(value)) return;
743
+ rewriteRunDirectoryPathFieldsAgainstRewrites(
744
+ value,
745
+ SOURCE_RUN_LOCATOR_FIELDS,
746
+ rewrites
747
+ );
748
+ }
749
+ function rewriteSummonsMaterials(value, rewrites) {
750
+ if (!isRecord(value)) return;
751
+ rewriteRunDirectoryPathFieldsAgainstRewrites(
752
+ value,
753
+ SUMMONS_PATH_FIELDS,
754
+ rewrites
755
+ );
756
+ rewriteSourceRunLocator(value.sourceRun, rewrites);
757
+ }
758
+ function rewriteAdmittedRoleRunPage(page, rewrites) {
759
+ rewriteRunDirectoryPathFieldsAgainstRewrites(page, ADMITTED_PAGE_PATH_FIELDS, rewrites);
760
+ rewriteSourceRunLocator(page.sourceRun, rewrites);
761
+ if (isRecord(page.principal)) {
762
+ rewriteRunDirectoryPathFieldsAgainstRewrites(
763
+ page.principal,
764
+ PRINCIPAL_SESSION_PATH_FIELDS,
765
+ rewrites
766
+ );
767
+ }
768
+ }
769
+ function projectRenderedPagePaths(page, actualRunDirectory) {
770
+ const stored = typeof page.runDirectory === "string" && page.runDirectory.trim() !== "" ? page.runDirectory : void 0;
771
+ if (stored === void 0 || stored === actualRunDirectory) return page;
772
+ const projected = structuredClone(page);
773
+ const rewrites = [
774
+ { oldRunDirectory: stored, newRunDirectory: actualRunDirectory }
775
+ ];
776
+ rewriteAdmittedRoleRunPage(projected, rewrites);
777
+ if (isRecord(projected.currentCourt)) {
778
+ rewriteSummonsMaterials(projected.currentCourt.summons, rewrites);
779
+ }
780
+ return projected;
781
+ }
782
+ var ADMITTED_PAGE_PATH_FIELDS, INVOCATION_PAGE_PATH_FIELDS, RUN_STATE_PAGE_PATH_FIELDS, PRINCIPAL_SESSION_PATH_FIELDS, SOURCE_RUN_LOCATOR_FIELDS, SUMMONS_PATH_FIELDS;
783
+ var init_role_run_path_rewrite = __esm({
784
+ "src/role-run-path-rewrite.ts"() {
785
+ "use strict";
786
+ init_unknown_value();
787
+ ADMITTED_PAGE_PATH_FIELDS = [
788
+ "runDirectory",
789
+ "admittedRequestPath",
790
+ // pre-#1161 pages only
791
+ "sessionDirectory",
792
+ "sessionFile",
793
+ // #1165/#1168: caller file-flag paths stay as given.
794
+ "mergerInputPath",
795
+ "sourceRunPath"
796
+ ];
797
+ INVOCATION_PAGE_PATH_FIELDS = [
798
+ "runDirectory",
799
+ "sessionDirectory",
800
+ "sessionFile"
801
+ ];
802
+ RUN_STATE_PAGE_PATH_FIELDS = [
803
+ "runDirectory",
804
+ "admittedRequestPath",
805
+ // pre-#1161 pages only
806
+ "sessionDirectory",
807
+ "sessionFile"
808
+ ];
809
+ PRINCIPAL_SESSION_PATH_FIELDS = [
810
+ "sessionDirectory",
811
+ "sessionFile"
812
+ ];
813
+ SOURCE_RUN_LOCATOR_FIELDS = ["runDirectory"];
814
+ SUMMONS_PATH_FIELDS = ["sourceRunPath"];
815
+ }
816
+ });
817
+
703
818
  // src/run-dossier-files.ts
704
819
  var RUN_CURRENT_FILE, RUN_HISTORY_FILE, RUN_LOG_FILE, RUN_STATE_FILE, RUN_HISTORY_KINDS, OFFICER_POINTER_RECORD_KIND, RUN_STATE_KINDS;
705
820
  var init_run_dossier_files = __esm({
@@ -1052,7 +1167,12 @@ function render(runDirectory, history, state, log, unreadable) {
1052
1167
  const whole = {};
1053
1168
  for (const section of ["invocation", "admitted", "runState", "terminal"]) {
1054
1169
  const page = lastPayloadOfKind(state, PAGE_ROW_KIND[section]);
1055
- if (page !== void 0) whole[section] = page;
1170
+ if (page === void 0) continue;
1171
+ if ((section === "invocation" || section === "admitted" || section === "runState") && isRecord(page)) {
1172
+ whole[section] = projectRenderedPagePaths(page, runDirectory);
1173
+ } else {
1174
+ whole[section] = page;
1175
+ }
1056
1176
  }
1057
1177
  let latest;
1058
1178
  for (const row of history) {
@@ -1167,6 +1287,7 @@ var init_run_dossier = __esm({
1167
1287
  "src/run-dossier.ts"() {
1168
1288
  "use strict";
1169
1289
  init_role_run_placement();
1290
+ init_role_run_path_rewrite();
1170
1291
  init_run_dossier_files();
1171
1292
  init_sitian_appender();
1172
1293
  init_sitian_reader();
@@ -9891,43 +10012,7 @@ var init_compliance_transport = __esm({
9891
10012
 
9892
10013
  // src/role-run-relocation.ts
9893
10014
  import { readdir as readdir2, readFile as readFile2, writeFile } from "node:fs/promises";
9894
- import { dirname as dirname5, join as join6, sep as sep2 } from "node:path";
9895
- function rewriteRunDirectoryPathValue(value, oldRunDirectory, newRunDirectory) {
9896
- if (typeof value !== "string") return value;
9897
- if (value === oldRunDirectory) return newRunDirectory;
9898
- const prefix = `${oldRunDirectory}${sep2}`;
9899
- if (value.startsWith(prefix)) {
9900
- return `${newRunDirectory}${value.slice(oldRunDirectory.length)}`;
9901
- }
9902
- return value;
9903
- }
9904
- function rewriteRunDirectoryPathValueAgainstRewrites(value, rewrites) {
9905
- if (typeof value !== "string" || rewrites.length === 0) return value;
9906
- let best;
9907
- for (const rewrite of rewrites) {
9908
- if (value === rewrite.oldRunDirectory || value.startsWith(`${rewrite.oldRunDirectory}${sep2}`)) {
9909
- if (best === void 0 || rewrite.oldRunDirectory.length > best.oldRunDirectory.length) {
9910
- best = rewrite;
9911
- }
9912
- }
9913
- }
9914
- if (best === void 0) return value;
9915
- return rewriteRunDirectoryPathValue(
9916
- value,
9917
- best.oldRunDirectory,
9918
- best.newRunDirectory
9919
- );
9920
- }
9921
- function rewriteRunDirectoryPathFieldsAgainstRewrites(record, fields, rewrites) {
9922
- for (const field of fields) {
9923
- if (field in record) {
9924
- record[field] = rewriteRunDirectoryPathValueAgainstRewrites(
9925
- record[field],
9926
- rewrites
9927
- );
9928
- }
9929
- }
9930
- }
10015
+ import { dirname as dirname5, join as join6 } from "node:path";
9931
10016
  function collectRewrites(input) {
9932
10017
  const own = {
9933
10018
  oldRunDirectory: input.oldRunDirectory,
@@ -9945,34 +10030,6 @@ function collectRewrites(input) {
9945
10030
  }
9946
10031
  return out;
9947
10032
  }
9948
- function rewriteSourceRunLocator(value, rewrites) {
9949
- if (!isRecord(value)) return;
9950
- rewriteRunDirectoryPathFieldsAgainstRewrites(
9951
- value,
9952
- SOURCE_RUN_LOCATOR_FIELDS,
9953
- rewrites
9954
- );
9955
- }
9956
- function rewriteSummonsMaterials(value, rewrites) {
9957
- if (!isRecord(value)) return;
9958
- rewriteRunDirectoryPathFieldsAgainstRewrites(
9959
- value,
9960
- SUMMONS_PATH_FIELDS,
9961
- rewrites
9962
- );
9963
- rewriteSourceRunLocator(value.sourceRun, rewrites);
9964
- }
9965
- function rewriteAdmittedRoleRunPage(page, rewrites) {
9966
- rewriteRunDirectoryPathFieldsAgainstRewrites(page, ADMITTED_PAGE_FIELDS, rewrites);
9967
- rewriteSourceRunLocator(page.sourceRun, rewrites);
9968
- if (isRecord(page.principal)) {
9969
- rewriteRunDirectoryPathFieldsAgainstRewrites(
9970
- page.principal,
9971
- PRINCIPAL_SESSION_PATH_FIELDS,
9972
- rewrites
9973
- );
9974
- }
9975
- }
9976
10033
  async function rewriteLegacyOfficerPointerFile(path, rewrites) {
9977
10034
  const page = JSON.parse(await readFile2(path, "utf8"));
9978
10035
  if (!isRecord(page) || page.kind !== "direct-officer-run-pointer") return;
@@ -10135,9 +10192,9 @@ async function rewriteRoleRunDurablePages(input) {
10135
10192
  const rewrites = collectRewrites(input);
10136
10193
  const pageRewriters = {
10137
10194
  admitted: (page) => rewriteAdmittedRoleRunPage(page, rewrites),
10138
- invocation: (page) => rewriteRunDirectoryPathFieldsAgainstRewrites(page, INVOCATION_PAGE_FIELDS, rewrites),
10195
+ invocation: (page) => rewriteRunDirectoryPathFieldsAgainstRewrites(page, INVOCATION_PAGE_PATH_FIELDS, rewrites),
10139
10196
  runState: (page) => {
10140
- rewriteRunDirectoryPathFieldsAgainstRewrites(page, RUN_STATE_PAGE_FIELDS, rewrites);
10197
+ rewriteRunDirectoryPathFieldsAgainstRewrites(page, RUN_STATE_PAGE_PATH_FIELDS, rewrites);
10141
10198
  if (isRecord(page.principal)) {
10142
10199
  rewriteRunDirectoryPathFieldsAgainstRewrites(
10143
10200
  page.principal,
@@ -10181,46 +10238,18 @@ async function rewriteRoleRunDurablePages(input) {
10181
10238
  }
10182
10239
  await rewriteNestedMachinePathPages(pagesDirectory, rewrites);
10183
10240
  }
10184
- var ADMITTED_PAGE_FIELDS, INVOCATION_PAGE_FIELDS, RUN_STATE_PAGE_FIELDS, PRINCIPAL_SESSION_PATH_FIELDS, SOURCE_RUN_LOCATOR_FIELDS, SUMMONS_PATH_FIELDS, OFFICER_POINTER_FIELDS, SITIAN_RECORD_FIELDS, SESSION_HEADER_FIELDS, BINDING_PARENT_FIELDS;
10241
+ var OFFICER_POINTER_FIELDS, SITIAN_RECORD_FIELDS, SESSION_HEADER_FIELDS, BINDING_PARENT_FIELDS;
10185
10242
  var init_role_run_relocation = __esm({
10186
10243
  "src/role-run-relocation.ts"() {
10187
10244
  "use strict";
10188
10245
  init_activation_ledger_topology();
10246
+ init_compliance_transport();
10189
10247
  init_run_lifecycle();
10190
10248
  init_role_run_placement();
10191
- init_compliance_transport();
10249
+ init_role_run_path_rewrite();
10192
10250
  init_run_dossier();
10193
10251
  init_unknown_value();
10194
- ADMITTED_PAGE_FIELDS = [
10195
- "runDirectory",
10196
- "admittedRequestPath",
10197
- // pre-#1161 pages only
10198
- "sessionDirectory",
10199
- "sessionFile",
10200
- // #1165/#1168: caller file-flag paths (requestManifestPath, prerequisitesPath)
10201
- // stay as given. Obsolete copy fields (taskPath/packetPath) are not rewritten —
10202
- // stock volumes keep their bytes; live relocate no longer maintains them.
10203
- "mergerInputPath",
10204
- "sourceRunPath"
10205
- ];
10206
- INVOCATION_PAGE_FIELDS = [
10207
- "runDirectory",
10208
- "sessionDirectory",
10209
- "sessionFile"
10210
- ];
10211
- RUN_STATE_PAGE_FIELDS = [
10212
- "runDirectory",
10213
- "admittedRequestPath",
10214
- // pre-#1161 pages only
10215
- "sessionDirectory",
10216
- "sessionFile"
10217
- ];
10218
- PRINCIPAL_SESSION_PATH_FIELDS = [
10219
- "sessionDirectory",
10220
- "sessionFile"
10221
- ];
10222
- SOURCE_RUN_LOCATOR_FIELDS = ["runDirectory"];
10223
- SUMMONS_PATH_FIELDS = ["sourceRunPath"];
10252
+ init_role_run_path_rewrite();
10224
10253
  OFFICER_POINTER_FIELDS = ["sessionFile", "runDirectory"];
10225
10254
  SITIAN_RECORD_FIELDS = ["sessionParent"];
10226
10255
  SESSION_HEADER_FIELDS = ["parentSession"];
@@ -397,7 +397,7 @@ export function createPiRoleTurnHost(config) {
397
397
  // bind projects host.sessions; copy records the landing. Host adapters do
398
398
  // not write current.json — public bind/settlement seams own that render.
399
399
  try {
400
- await syncTurnRequestLivePlacement(request);
400
+ await syncTurnRequestLivePlacement(request, config.principalAuthority);
401
401
  const { sessionFile, sessionDirectory } = config.principalAuthority.decode(request.principal);
402
402
  const sessionId = await readPiSessionHeaderId(sessionFile);
403
403
  if (sessionId !== undefined) {