@akagilnc/pi-workflow-roles 0.1.2043 → 0.1.2052

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.
@@ -47,6 +47,10 @@ import {
47
47
  } from "../merger-contracts.ts";
48
48
  import { sha256Hex } from "../sha256.ts";
49
49
  import { uuidv7 } from "../uuidv7.ts";
50
+ import {
51
+ appendEngineSessionMaterial,
52
+ type EngineSessionMaterial,
53
+ } from "../package-resources/engine-material.ts";
50
54
  import { CliUsageError } from "./cli-errors.ts";
51
55
  import {
52
56
  REJECTED_PUBLIC_SPELLINGS,
@@ -809,6 +813,7 @@ export async function admitJudgeInvocation(
809
813
  /** Build the Pi prompt transport for an admitted Judge request. */
810
814
  export function buildJudgeTransportPrompt(
811
815
  admitted: AdmittedJudgeInvocation,
816
+ engineMaterial?: EngineSessionMaterial,
812
817
  ): string {
813
818
  const lines: string[] = [admitted.instructionEmpty ? "" : admitted.instruction];
814
819
  if (admitted.attachments.length > 0) {
@@ -818,7 +823,7 @@ export function buildJudgeTransportPrompt(
818
823
  lines.push(`- ${attachment.frozenPath}`);
819
824
  }
820
825
  }
821
- return lines.join("\n");
826
+ return appendEngineSessionMaterial(lines, engineMaterial).join("\n");
822
827
  }
823
828
 
824
829
  /** Load admitted-request.json written at admission (Navigator work-context seam). */
@@ -1404,6 +1409,7 @@ export async function admitCollectorInvocation(
1404
1409
  export function buildCollectorTransportPrompt(
1405
1410
  _admitted: AdmittedCollectorInvocation,
1406
1411
  ): string {
1412
+ // Exact historical fixed kickoff bytes (one-shot observation).
1407
1413
  return COLLECTOR_FIXED_KICKOFF;
1408
1414
  }
1409
1415
 
@@ -6,6 +6,7 @@
6
6
  import { writeFile } from "node:fs/promises";
7
7
  import { join } from "node:path";
8
8
 
9
+ import { engineSessionMaterialFromOptions } from "../package-resources/engine-material.ts";
9
10
  import {
10
11
  runExplicitInternalActivation,
11
12
  type ExplicitInternalKnownFailure,
@@ -76,6 +77,8 @@ export type JudgeRunEnv = {
76
77
  piRunner?: ExplicitInternalPiRunner;
77
78
  /** Effective judge seat model (persistent/startup/invocation). */
78
79
  model?: SeatModelConfig;
80
+ /** Optional labor engine name (config→activation; session material only). */
81
+ engine?: string;
79
82
  /**
80
83
  * Credential presence for public providers (auth.json shape).
81
84
  * Used as the production-owned typed channel when a selected public provider
@@ -100,10 +103,15 @@ export function buildJudgeActivationExtraArgs(
100
103
  admitted: AdmittedJudgeInvocation,
101
104
  options: {
102
105
  model?: SeatModelConfig;
106
+ engine?: string;
107
+ packageRoot?: string;
103
108
  extraPiArgs?: readonly string[];
104
109
  } = {},
105
110
  ): string[] {
106
- const prompt = buildJudgeTransportPrompt(admitted);
111
+ const prompt = buildJudgeTransportPrompt(
112
+ admitted,
113
+ engineSessionMaterialFromOptions(options),
114
+ );
107
115
  return [
108
116
  "--no-skills",
109
117
  "--no-prompt-templates",
@@ -436,7 +444,9 @@ export async function runPublicJudge(
436
444
  }
437
445
 
438
446
  const extraArgs = buildJudgeActivationExtraArgs(admitted, {
447
+ packageRoot: env.packageRoot,
439
448
  ...(env.model === undefined ? {} : { model: env.model }),
449
+ ...(env.engine === undefined ? {} : { engine: env.engine }),
440
450
  ...(env.extraPiArgs === undefined ? {} : { extraPiArgs: env.extraPiArgs }),
441
451
  });
442
452
 
@@ -278,6 +278,20 @@ const GLOBAL_OPTIONS = [
278
278
  zh: "覆盖 thinking 档位:off|minimal|low|medium|high|xhigh|max。",
279
279
  },
280
280
  },
281
+ {
282
+ id: "engine",
283
+ owner: "global",
284
+ canonical: "--engine",
285
+ aliases: [],
286
+ valueMetavar: "name",
287
+ required: false,
288
+ repeatable: false,
289
+ form: "option",
290
+ description: {
291
+ en: "Optional Judge labor engine for this invocation (name must exist in packaged engine materials; judge-only).",
292
+ zh: "本调用可选 Judge 劳动引擎(名字须存在于包内引擎调法材料;仅 Judge)。",
293
+ },
294
+ },
281
295
  {
282
296
  id: "help",
283
297
  owner: "global",
@@ -24,6 +24,7 @@ import {
24
24
  import { installPackageOwnedToolRegistration } from "./package-owned-tool-idle.ts";
25
25
  import { installWorkerGitHooks } from "./worker-submission-gates.ts";
26
26
  import { createReceiptDeliveryPolicy, NO_RECEIPT_LIFECYCLE_ENTRY_TYPE, RECEIPT_DELIVERY_PROMPT } from "./receipt-delivery-policy.ts";
27
+ import { createOAuthKeepalive, type OAuthKeepaliveOptions } from "./oauth-keepalive.ts";
27
28
 
28
29
  import type { AnyCanonicalSkillBinding } from "./canonical-skill-binding.ts";
29
30
  import type { CollectorClock } from "./collector-evidence.ts";
@@ -506,6 +507,12 @@ export type RoleRuntimeDependencies = {
506
507
  /** Monotonic ms clock for update throttling; defaults to performance.now (not Date.now). */
507
508
  toolExecutionObservationMonoNow?(): number;
508
509
  toolExecutionObservationWriter?: ToolExecutionObservationWriter;
510
+ /**
511
+ * #351 OAuth keepalive: providers/interval/scheduler.
512
+ * Production extension root reads oauth-keepalive.json and passes providers here
513
+ * (default ["kimi-coding"] when the setting file is absent). Tests may inject.
514
+ */
515
+ oauthKeepalive?: OAuthKeepaliveOptions;
509
516
  };
510
517
 
511
518
  function abortContext(ctx: ExtensionContext): void {
@@ -577,6 +584,8 @@ export function createRoleRuntimeExtension(
577
584
  let reviewerOriginalRequest: string | undefined;
578
585
  let reviewerExpansionCaptured = false;
579
586
  let navigatorAttendance: NavigatorAttendanceDependency | undefined;
587
+ // #351: session-lifecycle owner for periodic OAuth refresh (orthogonal to role admission).
588
+ const oauthKeepalive = createOAuthKeepalive(dependencies.oauthKeepalive);
580
589
  let pendingNavigatorPresentation: { event: import("./navigator-attendance.ts").NavigatorEvent; report: import("./navigator-attendance.ts").NavigatorReport } | undefined;
581
590
  let pendingNavigatorSettlement: Promise<void> | undefined;
582
591
  let navigatorWorkContext: NavigatorWorkContext | undefined;
@@ -809,6 +818,8 @@ export function createRoleRuntimeExtension(
809
818
  }, { triggerTurn: false });
810
819
  });
811
820
  pi.on("session_shutdown", async () => {
821
+ // #351: stop OAuth keepalive first so shutdown yields zero further ticks.
822
+ oauthKeepalive.stop();
812
823
  // Flush any still-pending affirmative attendance before teardown. Accepted
813
824
  // grace-timeout paths normally emit on agent_settled; abort can skip that hook.
814
825
  const presentation = pendingNavigatorPresentation;
@@ -1043,6 +1054,9 @@ export function createRoleRuntimeExtension(
1043
1054
  pendingNavigatorSettlement = undefined;
1044
1055
  pendingInfrastructureToolCallIds.clear();
1045
1056
  navigatorWorkContext = undefined;
1057
+ // #351: OAuth keepalive is orthogonal to --ak-role; start before role early-return
1058
+ // so role-less sessions (and reload after shutdown stop) still keep tokens alive.
1059
+ oauthKeepalive.start(ctx);
1046
1060
  const rawRole = pi.getFlag(ROLE_FLAG.name);
1047
1061
  if (rawRole === undefined) return;
1048
1062
  const entry = PACKAGED_ROLE_REGISTRY.find(({ role }) => role === rawRole);