@akagilnc/pi-workflow-roles 0.1.4800 → 0.1.4870

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 (143) hide show
  1. package/dist/acp-host/production-host.js +19434 -18218
  2. package/dist/analyst-book-key.js +63 -0
  3. package/dist/analyst-cohort.js +167 -0
  4. package/dist/analyst-entry.js +320 -0
  5. package/dist/analyst-index.js +247 -0
  6. package/dist/analyst-ledger.js +561 -0
  7. package/dist/analyst-median.js +16 -0
  8. package/dist/analyst-metric-families/acceptance-success-rework.js +249 -0
  9. package/dist/analyst-metric-families/b2-frame-buckets-actions.js +189 -0
  10. package/dist/analyst-metric-families/gate-cycles.js +77 -0
  11. package/dist/analyst-metric-families/leg-wall-clock.js +56 -0
  12. package/dist/analyst-metric-families/round-timeline.js +126 -0
  13. package/dist/analyst-metric-families.js +23 -0
  14. package/dist/analyst-metric-family.js +11 -0
  15. package/dist/analyst-model-groups.js +135 -0
  16. package/dist/analyst-page.js +182 -0
  17. package/dist/atomic-write.js +23 -0
  18. package/dist/auditor-soul.js +1 -1
  19. package/dist/countersign-contracts.js +0 -2
  20. package/dist/diarist-contracts.js +0 -1
  21. package/dist/doctor-contracts.js +2 -2
  22. package/dist/gatekeeper-role.js +15 -16
  23. package/dist/gleaner-left-contracts.js +0 -2
  24. package/dist/headless-host/production-host.js +16967 -15749
  25. package/dist/host-contracts.js +0 -4
  26. package/dist/inspector-contracts.js +0 -2
  27. package/dist/institutional-resolution.js +4 -2
  28. package/dist/merger-contracts.js +0 -2
  29. package/dist/migrate-book-topology.js +3908 -3089
  30. package/dist/navigator-public-session.js +4 -3
  31. package/dist/notary-contracts.js +0 -2
  32. package/dist/package-contracts/auditor-output.js +0 -1
  33. package/dist/package-contracts/collector-output.js +0 -2
  34. package/dist/package-contracts/fixer-output.js +0 -2
  35. package/dist/package-contracts/gatekeeper-output.js +0 -2
  36. package/dist/package-contracts/judge-output.js +0 -2
  37. package/dist/package-contracts/navigator-output.js +0 -2
  38. package/dist/package-contracts/reviewer-output.js +0 -2
  39. package/dist/package-contracts/terminating-tools.js +32 -92
  40. package/dist/package-contracts/worker-output.js +0 -4
  41. package/dist/packaged-role-registry.js +518 -36
  42. package/dist/pi/role-turn-host.js +2 -1
  43. package/dist/public-cli/analyst-run.js +185 -0
  44. package/dist/public-cli/cli.js +885 -0
  45. package/dist/public-cli/config.js +12 -9
  46. package/dist/public-cli/countersign-run.js +4 -311
  47. package/dist/public-cli/instruction-seat-run.js +628 -158
  48. package/dist/public-cli/invocation.js +806 -1550
  49. package/dist/public-cli/main.js +6962 -9882
  50. package/dist/public-cli/option-definitions.js +51 -99
  51. package/dist/public-cli/post-admission.js +30 -2
  52. package/dist/public-cli/run-lifecycle.js +234 -353
  53. package/dist/public-cli/seat-ticket-binding.js +6 -0
  54. package/dist/public-cli/settlement.js +261 -675
  55. package/dist/public-cli/turn-request.js +76 -0
  56. package/dist/public-role-summons.js +38 -112
  57. package/dist/role-activation-flags.js +23 -45
  58. package/dist/secretariat-contracts.js +0 -2
  59. package/dist/session-identity.js +17 -8
  60. package/dist/session-opening-materials.js +3 -2
  61. package/extensions/role-runtime.ts +6 -80
  62. package/package.json +1 -1
  63. package/souls/coder.md +1 -2
  64. package/src/acp-host/role-turn-host.ts +4 -1
  65. package/src/analyst-metric-families/acceptance-success-rework.ts +3 -2
  66. package/src/auditor-role.ts +1 -2
  67. package/src/auditor-soul.ts +1 -1
  68. package/src/collector-role.ts +2 -2
  69. package/src/countersign-contracts.ts +0 -1
  70. package/src/countersign-role.ts +1 -1
  71. package/src/diarist-contracts.ts +0 -1
  72. package/src/diarist-role.ts +0 -1
  73. package/src/doctor-auditor.ts +1 -2
  74. package/src/doctor-contracts.ts +1 -1
  75. package/src/doctor-role.ts +3 -2
  76. package/src/external-host-turn-loop.ts +1 -1
  77. package/src/factory-board.ts +10 -7
  78. package/src/gatekeeper-role.ts +16 -10
  79. package/src/gleaner-left-contracts.ts +0 -1
  80. package/src/gleaner-left-role.ts +0 -1
  81. package/src/headless-host/role-turn-host.ts +7 -1
  82. package/src/host-contracts.ts +10 -6
  83. package/src/inspector-contracts.ts +0 -1
  84. package/src/inspector-role.ts +0 -2
  85. package/src/institutional-resolution.ts +6 -4
  86. package/src/judge-role.ts +3 -3
  87. package/src/merger-contracts.ts +0 -1
  88. package/src/merger-role.ts +2 -2
  89. package/src/navigator-public-session.ts +7 -6
  90. package/src/navigator-work-context.ts +6 -8
  91. package/src/notary-contracts.ts +0 -1
  92. package/src/notary-role.ts +2 -3
  93. package/src/package-contracts/auditor-output.ts +0 -1
  94. package/src/package-contracts/collector-output.ts +0 -1
  95. package/src/package-contracts/fixer-output.ts +0 -1
  96. package/src/package-contracts/gatekeeper-output.ts +0 -1
  97. package/src/package-contracts/judge-output.ts +0 -1
  98. package/src/package-contracts/navigator-output.ts +0 -1
  99. package/src/package-contracts/reviewer-output.ts +0 -1
  100. package/src/package-contracts/terminating-tools.ts +27 -99
  101. package/src/package-contracts/worker-output.ts +0 -2
  102. package/src/packaged-role-registry.ts +604 -35
  103. package/src/pi/role-turn-host.ts +2 -1
  104. package/src/public-cli/cli.ts +64 -259
  105. package/src/public-cli/config.ts +18 -10
  106. package/src/public-cli/countersign-run.ts +14 -449
  107. package/src/public-cli/instruction-seat-run.ts +758 -277
  108. package/src/public-cli/invocation.ts +1097 -2051
  109. package/src/public-cli/option-definitions.ts +62 -127
  110. package/src/public-cli/post-admission.ts +47 -2
  111. package/src/public-cli/run-lifecycle.ts +303 -613
  112. package/src/public-cli/seat-ticket-binding.ts +6 -0
  113. package/src/public-cli/settlement.ts +399 -1185
  114. package/src/public-cli/turn-request.ts +92 -1
  115. package/src/public-role-summons.ts +44 -128
  116. package/src/reviewer-role.ts +3 -2
  117. package/src/role-activation-flags.ts +20 -41
  118. package/src/role-runtime-dependencies.ts +25 -26
  119. package/src/role-runtime.ts +121 -232
  120. package/src/secretariat-contracts.ts +0 -1
  121. package/src/secretariat-role.ts +0 -2
  122. package/src/session-identity.ts +23 -8
  123. package/src/session-opening-materials.ts +2 -1
  124. package/src/worker-role.ts +3 -4
  125. package/dist/doctor-auditor.js +0 -25
  126. package/dist/public-cli/diarist-run.js +0 -130
  127. package/dist/public-cli/doctor-run.js +0 -87
  128. package/dist/public-cli/inspector-run.js +0 -151
  129. package/dist/public-cli/judge-run.js +0 -114
  130. package/dist/public-cli/notary-run.js +0 -174
  131. package/dist/public-cli/reviewer-run.js +0 -339
  132. package/src/public-cli/coder-run.ts +0 -255
  133. package/src/public-cli/collector-run.ts +0 -189
  134. package/src/public-cli/diarist-run.ts +0 -233
  135. package/src/public-cli/doctor-run.ts +0 -167
  136. package/src/public-cli/fixer-run.ts +0 -265
  137. package/src/public-cli/gleaner-left-run.ts +0 -167
  138. package/src/public-cli/inspector-run.ts +0 -261
  139. package/src/public-cli/judge-run.ts +0 -196
  140. package/src/public-cli/merger-run.ts +0 -294
  141. package/src/public-cli/notary-run.ts +0 -279
  142. package/src/public-cli/reviewer-run.ts +0 -480
  143. package/src/public-cli/secretariat-run.ts +0 -265
@@ -10,7 +10,8 @@ import { basename, delimiter, dirname, isAbsolute, join, resolve } from "node:pa
10
10
  import { platform } from "node:process";
11
11
  import { promisify } from "node:util";
12
12
  import { randomUUID } from "node:crypto";
13
- import { ExplicitInternalActivationError, isOfficerReviewSeat } from "../host-contracts.js";
13
+ import { ExplicitInternalActivationError } from "../host-contracts.js";
14
+ import { isOfficerReviewSeat } from "../packaged-role-registry.js";
14
15
  import { applyEngineChildEnv, ENGINE_MODEL_FLAG_NAME, normalizeEngineName } from "../engine-detour.js";
15
16
  import { projectActivationFlags } from "../role-activation-flags.js";
16
17
  import { encodeUserDialogueStdin } from "../user-dialogue-stdin.js";
@@ -0,0 +1,185 @@
1
+ /**
2
+ * Public analyst adapter (#336/#337/#338/#399): argv → typed query → runAnalyst family.
3
+ * Deterministic analysis seat — no Pi runner, no admission lease.
4
+ * Reuses existing CLI failure envelope (CliUsageError + structural reject +
5
+ * ControlledFailure).
6
+ * #399: issue query = book (cwd git common-dir) × optional --ticket N.
7
+ * Bare call = whole book; --project-root deleted; --model-groups public face disabled;
8
+ * no library-index bootstrap. Library model-groups kernel retained for follow-up.
9
+ * #337 sweep: exactly one typed JSON attachment → AnalystSweepModeInput → #329 kernel.
10
+ * #338: issue/cohort (+ library model-groups); sync compute-if-missing; whole-compute failure →
11
+ * ControlledFailure terminal (code/projectRoot/issueNumber/real cause).
12
+ * "Unobtrusive" binds #337 merge auto-trigger only, not this user-initiated query.
13
+ */
14
+ import { readFile } from "node:fs/promises";
15
+ import { isAbsolute, resolve } from "node:path";
16
+ import { Value } from "typebox/value";
17
+ import { ActivationGitRepositoryRequiredError, resolveBookKeyFromGit, } from "../activation-ledger-git.js";
18
+ import { errnoCode, physicalPathIdentity, resolveActivationLedgerHome, } from "../activation-ledger-topology.js";
19
+ import { exactUtf8 } from "../exact-utf8.js";
20
+ import { readOrComputeAnalystIssuePage, runAnalyst, analystSweepModeInputSchema, AnalystIssueComputeError, } from "../analyst-entry.js";
21
+ import { CliUsageError } from "./cli-errors.js";
22
+ import { presentControlledFailure, presentStructuralRejection } from "./settlement.js";
23
+ /**
24
+ * Resolve the issue-query book from cwd git common-dir (same owner as record layer).
25
+ * Non-git cwd fails loud — bare / --ticket both require a book identity.
26
+ */
27
+ export function resolveAnalystIssueBookKeyFromCwd(cwd = process.cwd()) {
28
+ try {
29
+ return resolveBookKeyFromGit(cwd);
30
+ }
31
+ catch (error) {
32
+ if (error instanceof ActivationGitRepositoryRequiredError) {
33
+ throw new CliUsageError("analyst issue query requires a git repository cwd (book = git common-dir); run inside a repository (bare = whole book, or --ticket N)", { cause: error });
34
+ }
35
+ throw error;
36
+ }
37
+ }
38
+ /**
39
+ * Build the sole library issue-mode input from public argv faces (#399).
40
+ * - bare → whole book from cwd git common-dir
41
+ * - --ticket N → issueNumber = ticketNumber = N inside that book (strict; no index)
42
+ * - --project-root rejected at parse (deleted unconditionally)
43
+ */
44
+ export async function buildAnalystIssueModeInputFromPublicArgv(parsed, _ledgerHome) {
45
+ const cwd = process.cwd();
46
+ const bookKey = resolveAnalystIssueBookKeyFromCwd(cwd);
47
+ const projectRoot = physicalPathIdentity(cwd);
48
+ const ticket = parsed.ticket;
49
+ if (ticket === undefined) {
50
+ return {
51
+ mode: "issue",
52
+ bookKey,
53
+ projectRoot,
54
+ };
55
+ }
56
+ return {
57
+ mode: "issue",
58
+ bookKey,
59
+ projectRoot,
60
+ ticketNumber: ticket,
61
+ issueNumber: ticket,
62
+ };
63
+ }
64
+ /**
65
+ * Attachment JSON → library AnalystSweepModeInput via the sole schema (#337).
66
+ * No parallel hand shape; rejects missing/extra/wrong-type fields only.
67
+ */
68
+ export function parseAnalystSweepModeInputFromJsonValue(value) {
69
+ if (!Value.Check(analystSweepModeInputSchema, value)) {
70
+ throw new CliUsageError("analyst sweep attachment must match AnalystSweepModeInput");
71
+ }
72
+ return value;
73
+ }
74
+ /**
75
+ * Load sweep typed input from exactly one public CLI attachment path.
76
+ * Rejects: wrong cardinality, unreadable path, non-UTF-8, JSON fail, field contract.
77
+ * Zero ledger writes — read-only path resolve + parse.
78
+ */
79
+ export async function buildAnalystSweepModeInputFromAttachmentPaths(attachmentPaths) {
80
+ if (attachmentPaths.length !== 1) {
81
+ throw new CliUsageError("analyst sweep requires exactly one --attach typed JSON attachment");
82
+ }
83
+ const sourcePath = attachmentPaths[0];
84
+ const absolute = isAbsolute(sourcePath) ? sourcePath : resolve(sourcePath);
85
+ let bytes;
86
+ try {
87
+ bytes = await readFile(absolute);
88
+ }
89
+ catch (error) {
90
+ throw new CliUsageError(`analyst sweep attachment is not a readable regular file: ${sourcePath}`, { cause: error });
91
+ }
92
+ let text;
93
+ try {
94
+ text = exactUtf8(bytes, "analyst sweep attachment");
95
+ }
96
+ catch (error) {
97
+ const detail = error instanceof Error ? error.message : String(error);
98
+ throw new CliUsageError(detail, { cause: error });
99
+ }
100
+ let parsed;
101
+ try {
102
+ parsed = JSON.parse(text);
103
+ }
104
+ catch (error) {
105
+ throw new CliUsageError("analyst sweep attachment is not valid JSON", { cause: error });
106
+ }
107
+ return parseAnalystSweepModeInputFromJsonValue(parsed);
108
+ }
109
+ /**
110
+ * Public analyst run path — parse → resolve → query → typed receipt on stdout.
111
+ * Issue (#336/#338 compute-if-missing), sweep (#337), cohort (#338).
112
+ * model-groups public face disabled at parse (#399); library kernel retained.
113
+ */
114
+ export async function runPublicAnalyst(argv, _env, io, parseAnalystArgv) {
115
+ try {
116
+ const parsed = parseAnalystArgv(argv);
117
+ // Machine home is package-owned (ADR 0048) — caller may supply explicit home in env.
118
+ const ledgerHome = resolveActivationLedgerHome(_env.home);
119
+ if (parsed.query === "sweep") {
120
+ const input = await buildAnalystSweepModeInputFromAttachmentPaths(parsed.attachmentPaths);
121
+ const result = await runAnalyst(input, { home: _env.home });
122
+ io.stdout(`${JSON.stringify(result, null, 2)}\n`);
123
+ return { exitCode: 0 };
124
+ }
125
+ if (parsed.query === "cohort") {
126
+ // #412: bare N → cwd book (same口径 as #399 --ticket); book:N stays explicit.
127
+ // No cross-book silent scan — callers pass book:N for another repo's issues.
128
+ // Cwd book resolution is lazy and resolved at most once: an all-book:N
129
+ // cohort never touches cwd Git, so a non-git cwd cannot reject a purely
130
+ // explicit cross-book query.
131
+ let defaultBookKey;
132
+ const resolveIssue = (token) => {
133
+ if (token.kind === "book-qualified") {
134
+ return { bookKey: token.bookKey, issueNumber: token.issueNumber };
135
+ }
136
+ defaultBookKey ??= resolveAnalystIssueBookKeyFromCwd();
137
+ return { bookKey: defaultBookKey, issueNumber: token.issueNumber };
138
+ };
139
+ const result = await runAnalyst({
140
+ mode: "cohort",
141
+ groups: [
142
+ {
143
+ groupLabel: parsed.groups[0].groupLabel,
144
+ issues: parsed.groups[0].issues.map(resolveIssue),
145
+ },
146
+ {
147
+ groupLabel: parsed.groups[1].groupLabel,
148
+ issues: parsed.groups[1].issues.map(resolveIssue),
149
+ },
150
+ ],
151
+ }, { home: _env.home });
152
+ io.stdout(`${JSON.stringify(result, null, 2)}\n`);
153
+ return { exitCode: 0 };
154
+ }
155
+ // issue query — compute-if-missing (#338); sole kernel on miss.
156
+ const input = await buildAnalystIssueModeInputFromPublicArgv(parsed, ledgerHome);
157
+ const result = await readOrComputeAnalystIssuePage(input, { home: _env.home });
158
+ io.stdout(`${JSON.stringify(result, null, 2)}\n`);
159
+ return { exitCode: 0 };
160
+ }
161
+ catch (error) {
162
+ if (error instanceof CliUsageError) {
163
+ presentStructuralRejection(error, io);
164
+ return { exitCode: 2 };
165
+ }
166
+ if (error instanceof AnalystIssueComputeError) {
167
+ // Existing ControlledFailure: details carry code/projectRoot/issueNumber;
168
+ // identity.code carries distinguishable real cause (errno). No parallel schema.
169
+ const code = errnoCode(error.cause);
170
+ presentControlledFailure({
171
+ cause: "output",
172
+ diagnostic: error.message,
173
+ ...(code === undefined ? {} : { identity: { code } }),
174
+ details: {
175
+ code: error.code,
176
+ bookKey: error.bookKey,
177
+ projectRoot: error.projectRoot,
178
+ ...(error.issueNumber === undefined ? {} : { issueNumber: error.issueNumber }),
179
+ },
180
+ }, io);
181
+ return { exitCode: 1 };
182
+ }
183
+ throw error;
184
+ }
185
+ }