@akagilnc/pi-workflow-roles 0.1.5593 → 0.1.5614

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 (58) hide show
  1. package/README.md +1 -1
  2. package/README.zh-CN.md +1 -1
  3. package/dist/acp-host/production-host.js +521 -707
  4. package/dist/compliance-transport.js +2 -5
  5. package/dist/doctor-auditor.js +1 -1
  6. package/dist/gatekeeper-role.js +1 -1
  7. package/dist/headless-host/production-host.js +505 -691
  8. package/dist/merger-contracts.js +6 -2
  9. package/dist/migrate-book-topology.js +5142 -10735
  10. package/dist/navigator-public-session.js +4 -4
  11. package/dist/navigator-work-base.js +5 -30
  12. package/dist/package-contracts/worker-output.js +1 -6
  13. package/dist/packaged-role-registry.js +9 -6
  14. package/dist/pi/role-turn-host.js +10 -1
  15. package/dist/public-cli/instruction-seat-run.js +133 -38
  16. package/dist/public-cli/invocation.js +38 -74
  17. package/dist/public-cli/main.js +18155 -18235
  18. package/dist/public-cli/option-definitions.js +21 -2
  19. package/dist/public-cli/post-admission.js +25 -24
  20. package/dist/public-cli/run-lifecycle.js +4 -43
  21. package/dist/public-cli/turn-request.js +4 -9
  22. package/dist/public-role-summons.js +5 -3
  23. package/dist/role-run-placement.js +7 -1
  24. package/dist/role-run-relocation.js +3 -4
  25. package/package.json +1 -1
  26. package/scripts/build-package.mjs +2 -4
  27. package/src/audited-run-identity.ts +30 -0
  28. package/src/compliance-transport.ts +1 -4
  29. package/src/doctor-auditor.ts +1 -1
  30. package/src/gatekeeper-role.ts +1 -1
  31. package/src/host-contracts.ts +6 -4
  32. package/src/merger-contracts.ts +6 -2
  33. package/src/merger-role.ts +11 -1
  34. package/src/navigator-attendance.ts +2 -2
  35. package/src/navigator-public-session.ts +9 -5
  36. package/src/navigator-work-base.ts +19 -34
  37. package/src/notary-role.ts +12 -21
  38. package/src/package-contracts/worker-output.ts +0 -8
  39. package/src/packaged-role-registry.ts +8 -7
  40. package/src/pi/role-turn-host.ts +11 -1
  41. package/src/public-cli/instruction-seat-run.ts +162 -42
  42. package/src/public-cli/invocation.ts +55 -93
  43. package/src/public-cli/option-definitions.ts +22 -2
  44. package/src/public-cli/post-admission.ts +30 -24
  45. package/src/public-cli/run-lifecycle.ts +4 -56
  46. package/src/public-cli/turn-request.ts +9 -8
  47. package/src/public-role-summons.ts +17 -6
  48. package/src/role-envelope.ts +4 -0
  49. package/src/role-run-placement.ts +10 -1
  50. package/src/role-run-relocation.ts +3 -4
  51. package/src/role-runtime-dependencies.ts +0 -2
  52. package/src/role-runtime.ts +54 -47
  53. package/src/worker-role.ts +11 -78
  54. package/dist/auditor-dossier-tool.js +0 -47
  55. package/dist/package-contracts/fixer-packet.js +0 -77
  56. package/packets/fixer-prerequisites.json +0 -6
  57. package/src/auditor-dossier-tool.ts +0 -63
  58. package/src/package-contracts/fixer-packet.ts +0 -91
@@ -1,63 +0,0 @@
1
- import { join, resolve } from "node:path";
2
-
3
- import { RUN_HISTORY_FILE, RUN_LOG_FILE, runCurrentPath } from "./run-dossier.ts";
4
- import type { AgentToolResult, ExtensionContext } from "@earendil-works/pi-coding-agent";
5
- import type { HostContext } from "./host-contracts.ts";
6
- import {
7
- runDirectoryOfSessionFile,
8
- sessionFileOf,
9
- } from "./role-run-placement.ts";
10
- import { Type } from "typebox";
11
-
12
- export const AUDITOR_DOSSIER_TOOL_NAME = "ak_get_run_dossier" as const;
13
-
14
- export type AuditorDossierLocation = {
15
- readonly runDirectory: string;
16
- readonly current: string;
17
- readonly parentSessionCandidate: string;
18
- readonly attachments: string;
19
- readonly log: string;
20
- readonly history: string;
21
- };
22
-
23
- /** Resolve the exact run binding already carried by the parent record session. */
24
- export function auditorRunDirectory(context: ExtensionContext | HostContext): string | undefined {
25
- const sessionFile = context.sessionManager?.getSessionFile?.();
26
- if (sessionFile === undefined) return undefined;
27
- // Sole layout: <run>/session/session.jsonl → climb two levels to the run directory.
28
- return resolve(runDirectoryOfSessionFile(sessionFile));
29
- }
30
-
31
- /** The one shared, run-bound dossier locator exposed to every auditor seat. */
32
- export function createAuditorDossierTool(
33
- runDirectory: string | undefined,
34
- ) {
35
- return {
36
- name: AUDITOR_DOSSIER_TOOL_NAME,
37
- description: "定位本审计席绑定的 run 卷宗及其证据入口。",
38
- // #836 r16 class 3: execute() ignores `_params` entirely — a closed root
39
- // only rejects the role for saying more.
40
- parameters: Type.Object({}, { additionalProperties: true }),
41
- async execute(_id: string, _params: unknown): Promise<AgentToolResult<AuditorDossierLocation | undefined>> {
42
- if (runDirectory === undefined) {
43
- return {
44
- content: [{ type: "text", text: "本审计席无绑定 run 卷宗记录。" }],
45
- details: undefined,
46
- };
47
- }
48
- // #836: whole run directory pointer — officer finds materials; no leaf preference (A7.2).
49
- const details: AuditorDossierLocation = {
50
- runDirectory,
51
- current: runCurrentPath(runDirectory),
52
- parentSessionCandidate: sessionFileOf(runDirectory),
53
- attachments: join(runDirectory, "attachments"),
54
- log: join(runDirectory, RUN_LOG_FILE),
55
- history: join(runDirectory, RUN_HISTORY_FILE),
56
- };
57
- return {
58
- content: [{ type: "text", text: JSON.stringify(details) }],
59
- details,
60
- };
61
- },
62
- };
63
- }
@@ -1,91 +0,0 @@
1
- import { Type, type Static } from "typebox";
2
- import { Value } from "typebox/value";
3
-
4
- import { isRecord } from "../unknown-value.ts";
5
-
6
- export const FIXER_PREREQUISITE_ID_PATTERN = "^[A-Za-z0-9][A-Za-z0-9._-]*$";
7
-
8
- export const fixerPrerequisiteSchema = Type.Object({
9
- id: Type.String({ pattern: FIXER_PREREQUISITE_ID_PATTERN }),
10
- requirement: Type.String({ pattern: "\\S" }),
11
- });
12
-
13
- export const fixerPrerequisitesSchema = Type.Array(fixerPrerequisiteSchema);
14
- export type FixerPrerequisite = Readonly<Static<typeof fixerPrerequisiteSchema>>;
15
- export type FixerInvocationInput = Readonly<{
16
- instructions: string;
17
- prerequisites: readonly FixerPrerequisite[];
18
- }>;
19
-
20
- function causeMessage(cause: unknown): string {
21
- if (cause instanceof Error) return cause.message;
22
- if (typeof cause === "string") return cause;
23
- try {
24
- return JSON.stringify(cause) ?? String(cause);
25
- } catch {
26
- return String(cause);
27
- }
28
- }
29
-
30
- export class FixerPacketValidationError extends Error {
31
- readonly code = "AK_INVALID_FIX_PACKET";
32
-
33
- constructor(cause?: unknown) {
34
- const prefix = "Fixer prerequisites or instructions violate the invocation contract";
35
- super(
36
- cause === undefined ? prefix : `${prefix}: ${causeMessage(cause)}`,
37
- cause === undefined ? undefined : { cause },
38
- );
39
- this.name = "FixerPacketValidationError";
40
- }
41
- }
42
-
43
- function fail(cause: unknown): never {
44
- throw new FixerPacketValidationError(cause);
45
- }
46
-
47
- function parseFailure(value: unknown): never {
48
- if (!Array.isArray(value)) fail(new Error("Fixer prerequisites must be a JSON array"));
49
- for (const entry of value) {
50
- if (!isRecord(entry)) {
51
- fail(new Error("Fixer prerequisite entry must be an object with id and requirement fields"));
52
- }
53
- if (
54
- typeof (entry as Record<string, unknown>).id !== "string" ||
55
- !(new RegExp(FIXER_PREREQUISITE_ID_PATTERN)).test((entry as { id: string }).id)
56
- ) {
57
- fail(new Error(`Fixer prerequisite id violates pattern ${FIXER_PREREQUISITE_ID_PATTERN}`));
58
- }
59
- if (
60
- typeof (entry as Record<string, unknown>).requirement !== "string" ||
61
- !/\S/.test((entry as { requirement: string }).requirement)
62
- ) {
63
- fail(new Error("Fixer prerequisite requirement must be nonblank"));
64
- }
65
- }
66
- fail(new Error("Fixer prerequisites violate the attachment schema"));
67
- }
68
-
69
- export function validateFixerPrerequisites(value: unknown): readonly FixerPrerequisite[] {
70
- if (!Value.Check(fixerPrerequisitesSchema, value)) parseFailure(value);
71
- const entries = value as Static<typeof fixerPrerequisitesSchema>;
72
- const ids = new Set<string>();
73
- const prerequisites = entries.map((entry) => {
74
- if (ids.has(entry.id)) {
75
- fail(new Error(`Fixer prerequisites contain duplicate id: ${entry.id}`));
76
- }
77
- ids.add(entry.id);
78
- return Object.freeze({ id: entry.id, requirement: entry.requirement });
79
- });
80
- return Object.freeze(prerequisites);
81
- }
82
-
83
- export function parseFixerPrerequisites(source: string): readonly FixerPrerequisite[] {
84
- let decoded: unknown;
85
- try {
86
- decoded = JSON.parse(source);
87
- } catch (error) {
88
- fail(error);
89
- }
90
- return validateFixerPrerequisites(decoded);
91
- }