@akagilnc/pi-workflow-roles 0.1.3663 → 0.1.3669

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,13 +1,16 @@
1
1
  /**
2
2
  * 系统随案递送本票起居录的中立指针段(ADR 0081 `automatic-case-material`;
3
+ * #709 公共入口通用递送与 #742 给事中受理链路同源;
3
4
  * 指针输入沿 ADR 0079 `summons-pointer-input`,不把卷宗正文塞进提示词)。
4
5
  * 只读已有案卷:不刷新、不生成、不校验内容、不新增拒收或停工条件。
5
6
  * 机器文本仅中立标识材料(ADR 0073),用途说明归角色材料所有。
7
+ *
8
+ * 递送挂载点唯一:`post-admission` 在 beforeDispatch 之后为每个公共入口追加本段。
6
9
  */
7
10
  import { stat } from "node:fs/promises";
8
11
  import { resolveTicketProvenanceVolume } from "../ticket-provenance.js";
9
- /** Section heading of the system-delivered dossier pointer. */
10
- export const CASE_DOSSIER_SECTION_HEADING = "## 本票起居录(系统随案提供)";
12
+ /** Section heading of the system-delivered dossier pointer (presentation only). */
13
+ const CASE_DOSSIER_SECTION_HEADING = "## 本票起居录(系统随案提供)";
11
14
  /** Honest one-line state of one dossier file: present, absent, or unreadable. */
12
15
  async function describeDossierFile(path) {
13
16
  try {
@@ -28326,167 +28326,6 @@ var init_collector_run = __esm({
28326
28326
  }
28327
28327
  });
28328
28328
 
28329
- // src/public-cli/countersign-run.ts
28330
- function buildCountersignTurnRequest(admitted, options) {
28331
- return projectRoleTurnRequest(
28332
- admitted,
28333
- {
28334
- activation: {
28335
- role: "countersign",
28336
- // Admitted typed binding rides the turn activation seam to the Notary gate.
28337
- ...admitted.ticketNumber === void 0 ? {} : { ticketNumber: admitted.ticketNumber }
28338
- }
28339
- },
28340
- options
28341
- );
28342
- }
28343
- async function runPublicCountersign(argv, env, io, parseCountersignArgv2) {
28344
- let parsed;
28345
- try {
28346
- parsed = parseCountersignArgv2(argv);
28347
- } catch (error) {
28348
- if (error instanceof CliUsageError) {
28349
- presentStructuralRejection(error, io);
28350
- return { exitCode: 2 };
28351
- }
28352
- throw error;
28353
- }
28354
- const projectRoot = parsed.project ?? env.cwd;
28355
- const reusedTicketNumber = await resolveKnownTicketNumber({
28356
- instruction: parsed.instruction,
28357
- projectRoot,
28358
- home: env.home
28359
- });
28360
- if (reusedTicketNumber !== void 0) {
28361
- const summons = {
28362
- instruction: parsed.instruction,
28363
- instructionEmpty: parsed.instruction.trim() === "",
28364
- attachmentPaths: parsed.attachmentPaths
28365
- };
28366
- const resumed = await tryResumeSameTicketSeatRun({
28367
- home: env.home,
28368
- projectRoot,
28369
- role: "countersign",
28370
- ticketNumber: reusedTicketNumber,
28371
- freshSummons: env.freshSummons,
28372
- summons,
28373
- resume: (runId, materials) => runPublicCountersignResume(
28374
- { runId, ...materials === void 0 ? {} : { summons: materials } },
28375
- env,
28376
- io
28377
- )
28378
- });
28379
- if (resumed !== void 0) return resumed;
28380
- }
28381
- let admitted;
28382
- try {
28383
- admitted = await admitCountersignInvocation({
28384
- home: env.home,
28385
- principalAuthority: env.principalAuthority,
28386
- cwd: env.cwd,
28387
- instruction: parsed.instruction,
28388
- attachmentPaths: parsed.attachmentPaths,
28389
- ...parsed.project === void 0 ? {} : { project: parsed.project },
28390
- ...env.createRunId === void 0 ? {} : { createRunId: env.createRunId },
28391
- ...env.model === void 0 ? {} : { model: env.model },
28392
- ...env.correlationId === void 0 ? {} : { correlationId: env.correlationId }
28393
- });
28394
- } catch (error) {
28395
- if (error instanceof CliUsageError) {
28396
- presentStructuralRejection(error, io);
28397
- return { exitCode: 2 };
28398
- }
28399
- throw error;
28400
- }
28401
- await markRunAdmitted(admitted, env.principalAuthority);
28402
- const turnProjection = {
28403
- packageRoot: env.packageRoot,
28404
- home: env.home,
28405
- agentDir: env.agentDir,
28406
- ...env.model === void 0 ? {} : { model: env.model },
28407
- ...env.engine === void 0 ? {} : { engine: env.engine },
28408
- ...env.timeoutMs === void 0 ? {} : { timeoutMs: env.timeoutMs },
28409
- ...env.correlationId === void 0 || env.correlationId.trim() === "" ? {} : { correlationId: env.correlationId },
28410
- continuation: {
28411
- kind: "initial",
28412
- prompt: buildCountersignTransportPrompt(
28413
- admitted,
28414
- engineSessionMaterialFromOptions({
28415
- ...env.engine === void 0 ? {} : { engine: env.engine },
28416
- packageRoot: env.packageRoot
28417
- })
28418
- )
28419
- }
28420
- };
28421
- const turnRequest = buildCountersignTurnRequest(admitted, turnProjection);
28422
- return await runPostAdmissionOneShot({
28423
- admitted,
28424
- env,
28425
- io,
28426
- request: turnRequest,
28427
- adapters: countersignAdapters({
28428
- beforeDispatch: async (admitted2) => {
28429
- await bindReusedTicketNumber(admitted2, reusedTicketNumber);
28430
- Object.assign(
28431
- turnRequest,
28432
- buildCountersignTurnRequest(admitted2, turnProjection)
28433
- );
28434
- }
28435
- }),
28436
- ...env.engine === void 0 ? {} : { effectiveEngine: env.engine }
28437
- });
28438
- }
28439
- function countersignAdapters(options) {
28440
- return {
28441
- trySettle: (admitted, authority, scope) => trySettleCountersignTerminalResult(admitted, authority, scope),
28442
- // Accepted receipts and failure terminals both present via shared path.
28443
- shouldPresentSettled: () => true,
28444
- ...options?.beforeDispatch === void 0 ? {} : { beforeDispatch: options.beforeDispatch }
28445
- };
28446
- }
28447
- async function runPublicCountersignResume(request, env, io) {
28448
- return await runPostAdmissionSeatResume({
28449
- request,
28450
- env,
28451
- io,
28452
- load: (effective) => loadResumableCountersignRun(
28453
- env.home,
28454
- effective.runId,
28455
- env.principalAuthority
28456
- ),
28457
- buildTurnRequest: async (admitted, effective) => {
28458
- const summonsPrepared = await prepareSummonsResumeMaterials(
28459
- admitted.runDirectory,
28460
- effective.summons
28461
- );
28462
- return buildCountersignTurnRequest(
28463
- admitted,
28464
- resumeTurnRequestProjectionOptions(
28465
- admitted,
28466
- effective,
28467
- env,
28468
- summonsPrepared
28469
- )
28470
- );
28471
- },
28472
- adapters: countersignAdapters(),
28473
- ...env.engine === void 0 ? {} : { effectiveEngine: env.engine }
28474
- });
28475
- }
28476
- var init_countersign_run = __esm({
28477
- "src/public-cli/countersign-run.ts"() {
28478
- "use strict";
28479
- init_engine_material();
28480
- init_cli_errors();
28481
- init_invocation();
28482
- init_seat_ticket_binding();
28483
- init_post_admission();
28484
- init_run_lifecycle();
28485
- init_settlement();
28486
- init_turn_request();
28487
- }
28488
- });
28489
-
28490
28329
  // src/diarist-mechanical.ts
28491
28330
  import { createHash as createHash6 } from "node:crypto";
28492
28331
  import { existsSync as existsSync9, readdirSync as readdirSync2, readFileSync as readFileSync3, realpathSync as realpathSync3, statSync as statSync2 } from "node:fs";
@@ -29013,6 +28852,12 @@ var init_diarist = __esm({
29013
28852
  });
29014
28853
 
29015
28854
  // src/public-cli/diarist-run.ts
28855
+ var diarist_run_exports = {};
28856
+ __export(diarist_run_exports, {
28857
+ buildDiaristTurnRequest: () => buildDiaristTurnRequest,
28858
+ runPublicDiarist: () => runPublicDiarist,
28859
+ runPublicDiaristResume: () => runPublicDiaristResume
28860
+ });
29016
28861
  import { existsSync as existsSync10 } from "node:fs";
29017
28862
  import { writeFile as writeFile7 } from "node:fs/promises";
29018
28863
  import { join as join26 } from "node:path";
@@ -29209,6 +29054,218 @@ var init_diarist_run = __esm({
29209
29054
  }
29210
29055
  });
29211
29056
 
29057
+ // src/public-cli/countersign-run.ts
29058
+ function buildCountersignTurnRequest(admitted, options) {
29059
+ return projectRoleTurnRequest(
29060
+ admitted,
29061
+ {
29062
+ activation: {
29063
+ role: "countersign",
29064
+ // Admitted typed binding rides the turn activation seam to the Notary gate.
29065
+ ...admitted.ticketNumber === void 0 ? {} : { ticketNumber: admitted.ticketNumber }
29066
+ }
29067
+ },
29068
+ options
29069
+ );
29070
+ }
29071
+ async function runCountersignCourtDiaristStation(admitted, env, io) {
29072
+ if (admitted.ticketNumber === void 0) return;
29073
+ if (env.runCourtDiaristStation !== void 0) {
29074
+ await env.runCourtDiaristStation(admitted);
29075
+ return;
29076
+ }
29077
+ const quietIo = {
29078
+ stdout() {
29079
+ },
29080
+ stderr(text) {
29081
+ if (text.trim() !== "") io.stderr(text);
29082
+ }
29083
+ };
29084
+ const { runPublicDiarist: runPublicDiarist2 } = await Promise.resolve().then(() => (init_diarist_run(), diarist_run_exports));
29085
+ const result2 = await runPublicDiarist2(
29086
+ [
29087
+ "--project",
29088
+ admitted.projectRoot,
29089
+ `\u6574\u7406 #${admitted.ticketNumber} \u7684\u672C\u6848\u4F9D\u636E\u3002`
29090
+ ],
29091
+ {
29092
+ home: env.home,
29093
+ agentDir: env.agentDir,
29094
+ packageRoot: env.packageRoot,
29095
+ cwd: env.cwd,
29096
+ principalAuthority: env.principalAuthority,
29097
+ roleTurnHost: env.roleTurnHost,
29098
+ sessionAppender: env.sessionAppender,
29099
+ ...env.model === void 0 ? {} : { model: env.model },
29100
+ ...env.engine === void 0 ? {} : { engine: env.engine },
29101
+ ...env.host === void 0 ? {} : { host: env.host },
29102
+ ...env.timeoutMs === void 0 ? {} : { timeoutMs: env.timeoutMs },
29103
+ ...env.credentials === void 0 ? {} : { credentials: env.credentials },
29104
+ ...env.correlationId === void 0 ? {} : { correlationId: env.correlationId },
29105
+ ...env.signal === void 0 ? {} : { signal: env.signal }
29106
+ },
29107
+ quietIo,
29108
+ parseDiaristArgv
29109
+ );
29110
+ if (result2.exitCode !== 0) {
29111
+ const detail = result2.terminal?.roleOutcome.kind === "failure" ? ` (roleOutcome=failure)` : "";
29112
+ throw new Error(
29113
+ `court diarist station failed for ticket #${admitted.ticketNumber}: exit ${result2.exitCode}${detail}`
29114
+ );
29115
+ }
29116
+ }
29117
+ async function runPublicCountersign(argv, env, io, parseCountersignArgv2) {
29118
+ let parsed;
29119
+ try {
29120
+ parsed = parseCountersignArgv2(argv);
29121
+ } catch (error) {
29122
+ if (error instanceof CliUsageError) {
29123
+ presentStructuralRejection(error, io);
29124
+ return { exitCode: 2 };
29125
+ }
29126
+ throw error;
29127
+ }
29128
+ const projectRoot = parsed.project ?? env.cwd;
29129
+ const reusedTicketNumber = await resolveKnownTicketNumber({
29130
+ instruction: parsed.instruction,
29131
+ projectRoot,
29132
+ home: env.home
29133
+ });
29134
+ if (reusedTicketNumber !== void 0) {
29135
+ const summons = {
29136
+ instruction: parsed.instruction,
29137
+ instructionEmpty: parsed.instruction.trim() === "",
29138
+ attachmentPaths: parsed.attachmentPaths
29139
+ };
29140
+ const resumed = await tryResumeSameTicketSeatRun({
29141
+ home: env.home,
29142
+ projectRoot,
29143
+ role: "countersign",
29144
+ ticketNumber: reusedTicketNumber,
29145
+ freshSummons: env.freshSummons,
29146
+ summons,
29147
+ resume: (runId, materials) => runPublicCountersignResume(
29148
+ { runId, ...materials === void 0 ? {} : { summons: materials } },
29149
+ env,
29150
+ io
29151
+ )
29152
+ });
29153
+ if (resumed !== void 0) return resumed;
29154
+ }
29155
+ let admitted;
29156
+ try {
29157
+ admitted = await admitCountersignInvocation({
29158
+ home: env.home,
29159
+ principalAuthority: env.principalAuthority,
29160
+ cwd: env.cwd,
29161
+ instruction: parsed.instruction,
29162
+ attachmentPaths: parsed.attachmentPaths,
29163
+ ...parsed.project === void 0 ? {} : { project: parsed.project },
29164
+ ...env.createRunId === void 0 ? {} : { createRunId: env.createRunId },
29165
+ ...env.model === void 0 ? {} : { model: env.model },
29166
+ ...env.correlationId === void 0 ? {} : { correlationId: env.correlationId }
29167
+ });
29168
+ } catch (error) {
29169
+ if (error instanceof CliUsageError) {
29170
+ presentStructuralRejection(error, io);
29171
+ return { exitCode: 2 };
29172
+ }
29173
+ throw error;
29174
+ }
29175
+ await markRunAdmitted(admitted, env.principalAuthority);
29176
+ const turnProjection = {
29177
+ packageRoot: env.packageRoot,
29178
+ home: env.home,
29179
+ agentDir: env.agentDir,
29180
+ ...env.model === void 0 ? {} : { model: env.model },
29181
+ ...env.engine === void 0 ? {} : { engine: env.engine },
29182
+ ...env.timeoutMs === void 0 ? {} : { timeoutMs: env.timeoutMs },
29183
+ ...env.correlationId === void 0 || env.correlationId.trim() === "" ? {} : { correlationId: env.correlationId },
29184
+ continuation: {
29185
+ kind: "initial",
29186
+ prompt: buildCountersignTransportPrompt(
29187
+ admitted,
29188
+ engineSessionMaterialFromOptions({
29189
+ ...env.engine === void 0 ? {} : { engine: env.engine },
29190
+ packageRoot: env.packageRoot
29191
+ })
29192
+ )
29193
+ }
29194
+ };
29195
+ const turnRequest = buildCountersignTurnRequest(admitted, turnProjection);
29196
+ return await runPostAdmissionOneShot({
29197
+ admitted,
29198
+ env,
29199
+ io,
29200
+ request: turnRequest,
29201
+ adapters: countersignAdapters({
29202
+ beforeDispatch: async (admittedSeat) => {
29203
+ await bindReusedTicketNumber(admittedSeat, reusedTicketNumber);
29204
+ Object.assign(
29205
+ turnRequest,
29206
+ buildCountersignTurnRequest(admittedSeat, turnProjection)
29207
+ );
29208
+ await runCountersignCourtDiaristStation(admittedSeat, env, io);
29209
+ }
29210
+ }),
29211
+ ...env.engine === void 0 ? {} : { effectiveEngine: env.engine }
29212
+ });
29213
+ }
29214
+ function countersignAdapters(options) {
29215
+ return {
29216
+ trySettle: (admitted, authority, scope) => trySettleCountersignTerminalResult(admitted, authority, scope),
29217
+ // Accepted receipts and failure terminals both present via shared path.
29218
+ shouldPresentSettled: () => true,
29219
+ ...options?.beforeDispatch === void 0 ? {} : { beforeDispatch: options.beforeDispatch }
29220
+ };
29221
+ }
29222
+ async function runPublicCountersignResume(request, env, io) {
29223
+ return await runPostAdmissionSeatResume({
29224
+ request,
29225
+ env,
29226
+ io,
29227
+ load: (effective) => loadResumableCountersignRun(
29228
+ env.home,
29229
+ effective.runId,
29230
+ env.principalAuthority
29231
+ ),
29232
+ buildTurnRequest: async (admitted, effective) => {
29233
+ const summonsPrepared = await prepareSummonsResumeMaterials(
29234
+ admitted.runDirectory,
29235
+ effective.summons
29236
+ );
29237
+ return buildCountersignTurnRequest(
29238
+ admitted,
29239
+ resumeTurnRequestProjectionOptions(
29240
+ admitted,
29241
+ effective,
29242
+ env,
29243
+ summonsPrepared
29244
+ )
29245
+ );
29246
+ },
29247
+ adapters: countersignAdapters({
29248
+ beforeDispatch: async (admitted) => {
29249
+ await runCountersignCourtDiaristStation(admitted, env, io);
29250
+ }
29251
+ }),
29252
+ ...env.engine === void 0 ? {} : { effectiveEngine: env.engine }
29253
+ });
29254
+ }
29255
+ var init_countersign_run = __esm({
29256
+ "src/public-cli/countersign-run.ts"() {
29257
+ "use strict";
29258
+ init_engine_material();
29259
+ init_cli_errors();
29260
+ init_invocation();
29261
+ init_seat_ticket_binding();
29262
+ init_post_admission();
29263
+ init_run_lifecycle();
29264
+ init_settlement();
29265
+ init_turn_request();
29266
+ }
29267
+ });
29268
+
29212
29269
  // src/public-cli/gleaner-left-run.ts
29213
29270
  function buildGleanerLeftTurnRequest(admitted, options) {
29214
29271
  return projectRoleTurnRequest(
@@ -163,11 +163,11 @@ export async function dispatchPostAdmissionTurn(input) {
163
163
  }
164
164
  }
165
165
  // Turn request is assembled after beforeDispatch so this turn sees whatever it
166
- // settled — the seat's ticket bind re-projection. Case dossier delivery
167
- // (ADR 0081) rides here for every public entry: first call, same-ticket
168
- // re-summons and manual resume alike. System refs append their own neutral
169
- // section; caller frozen attachments and the seat's own prompt bytes are
170
- // never rewritten.
166
+ // settled — the seat's ticket bind re-projection and any court diarist station
167
+ // writes (#742). Case dossier delivery (ADR 0081 / #709) rides here once for
168
+ // every public entry: first call, same-ticket re-summons and manual resume
169
+ // alike. System refs append their own neutral section; caller frozen
170
+ // attachments and the seat's own prompt bytes are never rewritten.
171
171
  let turnRequest = env.signal === undefined ? request : { ...request, signal: env.signal };
172
172
  if (hostTransition !== undefined) {
173
173
  turnRequest = { ...turnRequest, hostTransition };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akagilnc/pi-workflow-roles",
3
- "version": "0.1.3663",
3
+ "version": "0.1.3669",
4
4
  "description": "Soul-bound workflow roles for Pi",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -1,15 +1,18 @@
1
1
  /**
2
2
  * 系统随案递送本票起居录的中立指针段(ADR 0081 `automatic-case-material`;
3
+ * #709 公共入口通用递送与 #742 给事中受理链路同源;
3
4
  * 指针输入沿 ADR 0079 `summons-pointer-input`,不把卷宗正文塞进提示词)。
4
5
  * 只读已有案卷:不刷新、不生成、不校验内容、不新增拒收或停工条件。
5
6
  * 机器文本仅中立标识材料(ADR 0073),用途说明归角色材料所有。
7
+ *
8
+ * 递送挂载点唯一:`post-admission` 在 beforeDispatch 之后为每个公共入口追加本段。
6
9
  */
7
10
  import { stat } from "node:fs/promises";
8
11
 
9
12
  import { resolveTicketProvenanceVolume } from "../ticket-provenance.ts";
10
13
 
11
- /** Section heading of the system-delivered dossier pointer. */
12
- export const CASE_DOSSIER_SECTION_HEADING = "## 本票起居录(系统随案提供)" as const;
14
+ /** Section heading of the system-delivered dossier pointer (presentation only). */
15
+ const CASE_DOSSIER_SECTION_HEADING = "## 本票起居录(系统随案提供)" as const;
13
16
 
14
17
  /** Honest one-line state of one dossier file: present, absent, or unreadable. */
15
18
  async function describeDossierFile(path: string): Promise<string> {
@@ -1,9 +1,16 @@
1
1
  /**
2
- * Public Countersign Role run: admit ticket materials → shared post-admission
3
- * coordinator → settle Terminal result (#572 / ADR 0074). #599: manual resume
4
- * continues the exact session. Unbound admission reuses a known ticket identity
5
- * (#709). Who runs 起居郎, and when, is the caller's composition
6
- * (ADR 0010 / ADR 0075 `no-call-rule`) — not this seat's business.
2
+ * Public Countersign Role run: admit ticket materials → court-pipeline prior
3
+ * station (起居郎) → shared post-admission coordinator → settle Terminal result
4
+ * (#572 / ADR 0074 / ADR 0075 / #742). #599: manual resume continues the exact
5
+ * session. Unbound admission reuses a known ticket identity (#709) before the
6
+ * diary station.
7
+ *
8
+ * Court admission auto-runs 起居郎 first, then the countersign body — caller
9
+ * adds no diarist argv (L66672). This is the admission pipeline's prior station,
10
+ * not the countersign role calling 起居郎 (L66958 / L66966). Who may call 起居郎
11
+ * and in what order is not written into law (ADR 0075 `no-call-rule`); the
12
+ * present admission effect is what this seat currently does (L108315 目前是这样用的).
13
+ * 起居录 path delivery is owned once by post-admission (#709 / ADR 0081).
7
14
  */
8
15
  import type { DurablePrincipalAuthority, RoleTurnRequest } from "../host-contracts.ts";
9
16
  import { engineSessionMaterialFromOptions } from "../package-resources/engine-material.ts";
@@ -11,6 +18,7 @@ import { CliUsageError } from "./cli-errors.ts";
11
18
  import {
12
19
  admitCountersignInvocation,
13
20
  buildCountersignTransportPrompt,
21
+ parseDiaristArgv,
14
22
  type AdmittedCountersignInvocation,
15
23
  type ParseCountersignArgvResult,
16
24
  } from "./invocation.ts";
@@ -46,6 +54,13 @@ import {
46
54
  export type CountersignRunEnv = PostAdmissionEnv & {
47
55
  principalAuthority: DurablePrincipalAuthority;
48
56
  createRunId?: () => string;
57
+ /**
58
+ * Test seam: replace the court-pipeline 起居郎 station.
59
+ * Production leaves this unset and runs the public diarist seat.
60
+ */
61
+ runCourtDiaristStation?: (
62
+ admitted: AdmittedCountersignInvocation,
63
+ ) => Promise<void>;
49
64
  };
50
65
 
51
66
  /** Project admitted invocation onto the host-neutral turn request. */
@@ -68,6 +83,75 @@ export function buildCountersignTurnRequest(
68
83
  );
69
84
  }
70
85
 
86
+ /**
87
+ * Court-pipeline prior station: refresh this ticket's 起居录 before the
88
+ * countersign body turn (ADR 0075 `refresh-every-court`; #742 restore).
89
+ * Caller-invisible — no diarist argv on the countersign command line.
90
+ * Missing ticketNumber (true-unbound) skips the station — no diary is minted
91
+ * for a true-unbound run.
92
+ *
93
+ * Invokes the public 起居郎 seat so the book carries an `@diarist` run ahead of
94
+ * the countersign body. Station failure propagates (失败诚实 — no wash).
95
+ * Path delivery onto materials is not this station's job — post-admission owns it.
96
+ */
97
+ export async function runCountersignCourtDiaristStation(
98
+ admitted: AdmittedCountersignInvocation,
99
+ env: CountersignRunEnv,
100
+ io: CliIo,
101
+ ): Promise<void> {
102
+ if (admitted.ticketNumber === undefined) return;
103
+ if (env.runCourtDiaristStation !== undefined) {
104
+ await env.runCourtDiaristStation(admitted);
105
+ return;
106
+ }
107
+
108
+ // Quiet face: the countersign caller must not see diarist CLI chatter.
109
+ const quietIo: CliIo = {
110
+ stdout() {},
111
+ stderr(text: string) {
112
+ // Surface nested failures onto the parent stderr only; no success noise.
113
+ if (text.trim() !== "") io.stderr(text);
114
+ },
115
+ };
116
+
117
+ const { runPublicDiarist } = await import("./diarist-run.ts");
118
+ const result = await runPublicDiarist(
119
+ [
120
+ "--project",
121
+ admitted.projectRoot,
122
+ `整理 #${admitted.ticketNumber} 的本案依据。`,
123
+ ],
124
+ {
125
+ home: env.home,
126
+ agentDir: env.agentDir,
127
+ packageRoot: env.packageRoot,
128
+ cwd: env.cwd,
129
+ principalAuthority: env.principalAuthority,
130
+ roleTurnHost: env.roleTurnHost,
131
+ sessionAppender: env.sessionAppender,
132
+ ...(env.model === undefined ? {} : { model: env.model }),
133
+ ...(env.engine === undefined ? {} : { engine: env.engine }),
134
+ ...(env.host === undefined ? {} : { host: env.host }),
135
+ ...(env.timeoutMs === undefined ? {} : { timeoutMs: env.timeoutMs }),
136
+ ...(env.credentials === undefined ? {} : { credentials: env.credentials }),
137
+ ...(env.correlationId === undefined ? {} : { correlationId: env.correlationId }),
138
+ ...(env.signal === undefined ? {} : { signal: env.signal }),
139
+ },
140
+ quietIo,
141
+ parseDiaristArgv,
142
+ );
143
+
144
+ if (result.exitCode !== 0) {
145
+ const detail =
146
+ result.terminal?.roleOutcome.kind === "failure"
147
+ ? ` (roleOutcome=failure)`
148
+ : "";
149
+ throw new Error(
150
+ `court diarist station failed for ticket #${admitted.ticketNumber}: exit ${result.exitCode}${detail}`,
151
+ );
152
+ }
153
+ }
154
+
71
155
  export async function runPublicCountersign(
72
156
  argv: readonly string[],
73
157
  env: CountersignRunEnv,
@@ -174,13 +258,16 @@ export async function runPublicCountersign(
174
258
  io,
175
259
  request: turnRequest,
176
260
  adapters: countersignAdapters({
177
- beforeDispatch: async (admitted) => {
261
+ beforeDispatch: async (admittedSeat) => {
178
262
  // #635/#709: bind the reused identity inside the controlled-failure boundary.
179
- await bindReusedTicketNumber(admitted, reusedTicketNumber);
263
+ await bindReusedTicketNumber(admittedSeat, reusedTicketNumber);
180
264
  Object.assign(
181
265
  turnRequest,
182
- buildCountersignTurnRequest(admitted, turnProjection),
266
+ buildCountersignTurnRequest(admittedSeat, turnProjection),
183
267
  );
268
+ // Court station after bind so the diarist round sees the ticket.
269
+ // Dossier pointer delivery rides post-admission after this hook (#709).
270
+ await runCountersignCourtDiaristStation(admittedSeat, env, io);
184
271
  },
185
272
  }),
186
273
  ...(env.engine === undefined ? {} : { effectiveEngine: env.engine }),
@@ -208,9 +295,11 @@ function countersignAdapters(options?: {
208
295
 
209
296
  /**
210
297
  * Resume a previously admitted Countersign run (#599 / DK-3 / #637).
211
- * Restores role/ticket/session identity. Same-ticket summons deliver this turn's
212
- * instruction + frozen attachments on the resume prompt; manual resume keeps
213
- * package-envelope / caller-message semantics and birth attachments.
298
+ * Restores role/ticket/session identity. Every court re-entry runs the diarist
299
+ * station first (ADR 0075 `refresh-every-court`). Same-ticket summons deliver this
300
+ * turn's instruction + frozen attachments on the resume prompt; manual resume
301
+ * keeps package-envelope / caller-message semantics and birth attachments.
302
+ * 起居录 path delivery remains post-admission's single mount (#709).
214
303
  */
215
304
  export async function runPublicCountersignResume(
216
305
  request: PublicResumeRequest,
@@ -246,7 +335,11 @@ export async function runPublicCountersignResume(
246
335
  ),
247
336
  );
248
337
  },
249
- adapters: countersignAdapters(),
338
+ adapters: countersignAdapters({
339
+ beforeDispatch: async (admitted) => {
340
+ await runCountersignCourtDiaristStation(admitted, env, io);
341
+ },
342
+ }),
250
343
  ...(env.engine === undefined ? {} : { effectiveEngine: env.engine }),
251
344
  });
252
345
  }
@@ -362,11 +362,11 @@ export async function dispatchPostAdmissionTurn<
362
362
  }
363
363
 
364
364
  // Turn request is assembled after beforeDispatch so this turn sees whatever it
365
- // settled — the seat's ticket bind re-projection. Case dossier delivery
366
- // (ADR 0081) rides here for every public entry: first call, same-ticket
367
- // re-summons and manual resume alike. System refs append their own neutral
368
- // section; caller frozen attachments and the seat's own prompt bytes are
369
- // never rewritten.
365
+ // settled — the seat's ticket bind re-projection and any court diarist station
366
+ // writes (#742). Case dossier delivery (ADR 0081 / #709) rides here once for
367
+ // every public entry: first call, same-ticket re-summons and manual resume
368
+ // alike. System refs append their own neutral section; caller frozen
369
+ // attachments and the seat's own prompt bytes are never rewritten.
370
370
  let turnRequest: RoleTurnRequest =
371
371
  env.signal === undefined ? request : { ...request, signal: env.signal };
372
372
  if (hostTransition !== undefined) {