@akagilnc/pi-workflow-roles 0.1.3452 → 0.1.3471

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.
Files changed (36) hide show
  1. package/CLAUDE.md +2 -0
  2. package/dist/evidence-child-executor.js +2 -11
  3. package/dist/grok/production-host.js +196 -205
  4. package/dist/pi/in-process-session.js +4 -0
  5. package/dist/public-cli/main.js +998 -920
  6. package/package.json +1 -1
  7. package/scripts/build-package.mjs +1 -3
  8. package/src/analyst-gate-cycles-read.ts +3 -21
  9. package/src/analyst-ledger.ts +11 -42
  10. package/src/archivist-record-entry.ts +5 -6
  11. package/src/evidence-child-executor.ts +5 -15
  12. package/src/grok/production-host.ts +3 -32
  13. package/src/grok/role-envelope.ts +10 -4
  14. package/src/host-contracts.ts +4 -11
  15. package/src/host-transition-prior-native.ts +3 -7
  16. package/src/ledger-session-read.ts +1 -17
  17. package/src/pi/in-process-session.ts +6 -2
  18. package/src/pi/role-turn-host.ts +9 -0
  19. package/src/public-cli/collector-run.ts +4 -4
  20. package/src/public-cli/countersign-run.ts +90 -20
  21. package/src/public-cli/doctor-run.ts +4 -4
  22. package/src/public-cli/gleaner-left-run.ts +9 -6
  23. package/src/public-cli/inspector-run.ts +95 -32
  24. package/src/public-cli/instruction-seat-run.ts +7 -6
  25. package/src/public-cli/invocation.ts +14 -8
  26. package/src/public-cli/judge-run.ts +4 -4
  27. package/src/public-cli/notary-run.ts +91 -30
  28. package/src/public-cli/post-admission.ts +424 -360
  29. package/src/public-cli/run-lifecycle.ts +205 -0
  30. package/src/public-cli/seat-ticket-binding.ts +136 -16
  31. package/src/public-cli/settlement.ts +74 -52
  32. package/src/run-ticket-number.ts +53 -0
  33. package/src/submission-ledger.ts +86 -18
  34. package/dist/ledger-session-read.js +0 -241
  35. package/dist/ticket-seat-memory.js +0 -244
  36. package/src/ticket-seat-memory.ts +0 -454
@@ -2,17 +2,23 @@
2
2
  * Public Notary Role run: admit source-run locator → shared post-admission coordinator
3
3
  * → settle Terminal result (#448 / #517). Zero caller prompt/attachment. Lifecycle is
4
4
  * the shared post-admission seam; this module keeps only Notary adapters.
5
+ * #637: same-ticket re-summons resume the seat's previous run (no new run).
5
6
  */
6
7
  import type { DurablePrincipalAuthority, RoleTurnRequest } from "../host-contracts.ts";
8
+ import {
9
+ NotarySourceRunError,
10
+ resolveNotarySourceRunLocator,
11
+ } from "../notary-source-run.ts";
7
12
  import { engineSessionMaterialFromOptions } from "../package-resources/engine-material.ts";
8
- import { rebindAdmittedToTicketSeatMemory } from "../ticket-seat-memory.ts";
13
+ import { readRunTicketNumber } from "../run-ticket-number.ts";
9
14
  import { CliUsageError } from "./cli-errors.ts";
10
15
  import {
11
16
  admitNotaryInvocation,
12
17
  buildNotaryTransportPrompt,
13
18
  type AdmittedNotaryInvocation,
14
- type ParseNotaryArgvResult
19
+ type ParseNotaryArgvResult,
15
20
  } from "./invocation.ts";
21
+ import { tryResumeSameTicketSeatRun } from "./seat-ticket-binding.ts";
16
22
  import {
17
23
  runPostAdmissionOneShot,
18
24
  type PostAdmissionAdapters,
@@ -24,6 +30,7 @@ import {
24
30
  loadResumableNotaryRun,
25
31
  markRunAdmitted,
26
32
  type PublicResumeRequest,
33
+ type SameTicketSummonsMaterials,
27
34
  } from "./run-lifecycle.ts";
28
35
  import {
29
36
  presentStructuralRejection,
@@ -72,9 +79,59 @@ export async function runPublicNotary(
72
79
  admitted?: AdmittedNotaryInvocation;
73
80
  terminal?: TerminalResult;
74
81
  }> {
82
+ let parsed: ParseNotaryArgvResult;
83
+ try {
84
+ parsed = parseNotaryArgv(argv);
85
+ } catch (error) {
86
+ if (error instanceof CliUsageError) {
87
+ presentStructuralRejection(error, io);
88
+ return { exitCode: 2 };
89
+ }
90
+ throw error;
91
+ }
92
+
93
+ // #637: same ticket → resume prior notary run with this summons' source-run pointer.
94
+ // Source-run structural failures stay usage rejections; lookup/resume failures surface
95
+ // (no bare catch→fresh). Only true absence of a prior run mints new.
96
+ const projectRoot = parsed.project ?? env.cwd;
97
+ let source;
98
+ try {
99
+ source = await resolveNotarySourceRunLocator({
100
+ projectRoot,
101
+ sourceRun: parsed.sourceRun,
102
+ home: env.home,
103
+ });
104
+ } catch (error) {
105
+ if (error instanceof NotarySourceRunError) {
106
+ presentStructuralRejection(new CliUsageError(error.message, { cause: error }), io);
107
+ return { exitCode: 2 };
108
+ }
109
+ throw error;
110
+ }
111
+ const ticketNumber = await readRunTicketNumber(source.runDirectory);
112
+ if (ticketNumber !== undefined) {
113
+ const summons: SameTicketSummonsMaterials = {
114
+ sourceRunPath: source.runDirectory,
115
+ sourceRun: source,
116
+ };
117
+ const resumed = await tryResumeSameTicketSeatRun({
118
+ home: env.home,
119
+ projectRoot,
120
+ role: "notary",
121
+ ticketNumber,
122
+ summons,
123
+ resume: (runId, materials) =>
124
+ runPublicNotaryResume(
125
+ { runId, ...(materials === undefined ? {} : { summons: materials }) },
126
+ env,
127
+ io,
128
+ ),
129
+ });
130
+ if (resumed !== undefined) return resumed;
131
+ }
132
+
75
133
  let admitted: AdmittedNotaryInvocation;
76
134
  try {
77
- const parsed = parseNotaryArgv(argv);
78
135
  admitted = await admitNotaryInvocation({
79
136
  home: env.home,
80
137
  principalAuthority: env.principalAuthority,
@@ -93,27 +150,12 @@ export async function runPublicNotary(
93
150
  throw error;
94
151
  }
95
152
 
96
- // #636: ticket from source-run → continue ticket+seat memory principal across runs.
97
- // Rebind before admitted mark so run-state session paths name the memory principal.
98
- // Existing nest → continuation.kind=resume so real hosts reopen native volume (Grok
99
- // session/load; Pi/Grok hostTransition path handoff). Same-ticket rebind alone is not resume.
100
- const memory = await rebindAdmittedToTicketSeatMemory({
101
- admitted,
102
- seat: "notary",
103
- principalAuthority: env.principalAuthority,
104
- });
105
153
  await markRunAdmitted(admitted, env.principalAuthority);
106
154
 
107
155
  const engineMaterial = engineSessionMaterialFromOptions({
108
156
  ...(env.engine === undefined ? {} : { engine: env.engine }),
109
157
  packageRoot: env.packageRoot,
110
158
  });
111
- // Prompt is the same officer transport; only continuation kind flips (#636 / ADR 0079).
112
- const continuation = {
113
- kind: memory?.resumed === true ? ("resume" as const) : ("initial" as const),
114
- prompt: buildNotaryTransportPrompt(admitted, engineMaterial),
115
- };
116
-
117
159
  const turnRequest = buildNotaryTurnRequest(admitted, {
118
160
  packageRoot: env.packageRoot,
119
161
  home: env.home,
@@ -124,7 +166,10 @@ export async function runPublicNotary(
124
166
  ...(env.correlationId === undefined || env.correlationId.trim() === ""
125
167
  ? {}
126
168
  : { correlationId: env.correlationId }),
127
- continuation,
169
+ continuation: {
170
+ kind: "initial",
171
+ prompt: buildNotaryTransportPrompt(admitted, engineMaterial),
172
+ },
128
173
  });
129
174
 
130
175
  return await runPostAdmissionOneShot({
@@ -139,15 +184,16 @@ export async function runPublicNotary(
139
184
 
140
185
  function notaryAdapters(): PostAdmissionAdapters<AdmittedNotaryInvocation> {
141
186
  return {
142
- trySettle: (admitted, authority) => trySettleNotaryTerminalResult(admitted, authority),
187
+ trySettle: (admitted, authority, scope) => trySettleNotaryTerminalResult(admitted, authority, scope),
143
188
  // Accepted receipts and failure terminals both present via shared path.
144
189
  shouldPresentSettled: () => true,
145
190
  };
146
191
  }
147
192
 
148
193
  /**
149
- * Resume a previously admitted Notary run (#633). Source-run locator restores
150
- * from the durable admitted request (never re-resolved); the session principal reopens.
194
+ * Resume a previously admitted Notary run (#633 / #637). Manual resume restores
195
+ * source-run from the durable admitted request. Same-ticket re-summons deliver
196
+ * this turn's source-run activation pointer while reopening the same session.
151
197
  */
152
198
  export async function runPublicNotaryResume(
153
199
  request: PublicResumeRequest,
@@ -162,22 +208,37 @@ export async function runPublicNotaryResume(
162
208
  request,
163
209
  env,
164
210
  io,
165
- load: () => {
166
- if (request.message !== undefined) {
211
+ load: async (effective) => {
212
+ if (effective.message !== undefined) {
167
213
  throw new CliUsageError(
168
214
  "notary rejects caller prompt/instruction; only zero caller-prompt continuation admitted",
169
215
  );
170
216
  }
171
- return loadResumableNotaryRun(
217
+ const loaded = await loadResumableNotaryRun(
172
218
  env.home,
173
- request.runId,
219
+ effective.runId,
174
220
  env.principalAuthority,
175
221
  );
222
+ const summons = effective.summons;
223
+ if (
224
+ summons?.sourceRunPath !== undefined &&
225
+ summons.sourceRun !== undefined
226
+ ) {
227
+ return {
228
+ admitted: {
229
+ ...loaded.admitted,
230
+ sourceRunPath: summons.sourceRunPath,
231
+ sourceRun: summons.sourceRun,
232
+ },
233
+ };
234
+ }
235
+ return loaded;
176
236
  },
177
- buildTurnRequest: (admitted) => buildNotaryTurnRequest(
178
- admitted,
179
- resumeTurnRequestProjectionOptions(admitted, request, env),
180
- ),
237
+ buildTurnRequest: (admitted, effective) =>
238
+ buildNotaryTurnRequest(
239
+ admitted,
240
+ resumeTurnRequestProjectionOptions(admitted, effective, env),
241
+ ),
181
242
  adapters: notaryAdapters(),
182
243
  ...(env.engine === undefined ? {} : { effectiveEngine: env.engine }),
183
244
  });