pi-harness-runtime 1.1.407 → 1.1.408

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 (166) hide show
  1. package/index.ts +78 -0
  2. package/package.json +1 -1
  3. package/packages/a2a-adapter/package.json +1 -1
  4. package/packages/agent-policy/package.json +1 -1
  5. package/packages/architecture-generator/package.json +1 -1
  6. package/packages/auth/package.json +1 -1
  7. package/packages/autonomous-refactor/package.json +1 -1
  8. package/packages/autonomous-runtime/package.json +1 -1
  9. package/packages/cache-strategy/package.json +1 -1
  10. package/packages/capability-registry/package.json +1 -1
  11. package/packages/checkpoint/package.json +1 -1
  12. package/packages/cli-plugin-sdk/package.json +1 -1
  13. package/packages/clipboard/package.json +1 -1
  14. package/packages/clipboard-plugin/package.json +1 -1
  15. package/packages/code-generation/package.json +1 -1
  16. package/packages/code-review/package.json +1 -1
  17. package/packages/codex-adapter/package.json +1 -1
  18. package/packages/codex-watcher/package.json +1 -1
  19. package/packages/config-capture/package.json +1 -1
  20. package/packages/connection-runtime/package.json +1 -1
  21. package/packages/context-compiler/package.json +1 -1
  22. package/packages/context-discovery/package.json +1 -1
  23. package/packages/context-manager/package.json +1 -1
  24. package/packages/contracts/package.json +1 -1
  25. package/packages/cookie-sanitizer/package.json +1 -1
  26. package/packages/cost-optimizer/package.json +1 -1
  27. package/packages/dependency-analyzer/package.json +1 -1
  28. package/packages/django-plugin/package.json +1 -1
  29. package/packages/doc-generator/package.json +1 -1
  30. package/packages/durable-review/package.json +1 -1
  31. package/packages/e2e-tester/package.json +1 -1
  32. package/packages/evaluation-engine/package.json +1 -1
  33. package/packages/evaluation-runner/package.json +1 -1
  34. package/packages/event-bus/package.json +1 -1
  35. package/packages/event-sink/package.json +1 -1
  36. package/packages/event-store/package.json +1 -1
  37. package/packages/experience-replay/package.json +1 -1
  38. package/packages/feedback-collector/package.json +1 -1
  39. package/packages/file-copy-helper/package.json +1 -1
  40. package/packages/framework-detector/package.json +1 -1
  41. package/packages/framework-plugin-sdk/package.json +1 -1
  42. package/packages/frappe-plugin/package.json +1 -1
  43. package/packages/generic-web-plugin/package.json +1 -1
  44. package/packages/health-monitor/package.json +1 -1
  45. package/packages/intent-analyzer/package.json +1 -1
  46. package/packages/jev-judge/package.json +1 -1
  47. package/packages/knowledge-graph/package.json +1 -1
  48. package/packages/knowledge-retrieval/package.json +1 -1
  49. package/packages/laravel-plugin/package.json +1 -1
  50. package/packages/learning-engine/package.json +1 -1
  51. package/packages/logging/package.json +1 -1
  52. package/packages/mcp-adapter/package.json +1 -1
  53. package/packages/memory-engine/package.json +1 -1
  54. package/packages/milestone-manager/package.json +1 -1
  55. package/packages/model-registry/package.json +1 -1
  56. package/packages/nextjs-plugin/package.json +1 -1
  57. package/packages/notification/package.json +1 -1
  58. package/packages/observability/package.json +1 -1
  59. package/packages/okf-indexer/package.json +1 -1
  60. package/packages/paperclip-integration/package.json +1 -1
  61. package/packages/performance-optimizer/package.json +1 -1
  62. package/packages/permission-mode/package.json +1 -1
  63. package/packages/privilege-broker/package.json +1 -1
  64. package/packages/project-analyzer/package.json +1 -1
  65. package/packages/project-bootstrap/package.json +1 -1
  66. package/packages/projection-engine/package.json +1 -1
  67. package/packages/prompt-compiler/package.json +1 -1
  68. package/packages/prompt-versioning/package.json +1 -1
  69. package/packages/provider-adapter-sdk/package.json +1 -1
  70. package/packages/provider-router/package.json +1 -1
  71. package/packages/provider-selector/package.json +1 -1
  72. package/packages/providers/package.json +1 -1
  73. package/packages/qdrant-skills/package.json +1 -1
  74. package/packages/quota-manager/package.json +1 -1
  75. package/packages/rate-limiter/package.json +1 -1
  76. package/packages/react-vite-plugin/package.json +1 -1
  77. package/packages/relay/package.json +1 -1
  78. package/packages/release-manager/package.json +1 -1
  79. package/packages/requirement-compiler/package.json +1 -1
  80. package/packages/runtime/package.json +1 -1
  81. package/packages/scheduler/package.json +1 -1
  82. package/packages/scheduler-adapter/package.json +1 -1
  83. package/packages/session/package.json +1 -1
  84. package/packages/session-api/package.json +1 -1
  85. package/packages/session-export/package.json +1 -1
  86. package/packages/shared-context/package.json +1 -1
  87. package/packages/skill-mcp-client/package.json +1 -1
  88. package/packages/skill-registry/package.json +1 -1
  89. package/packages/skills/package.json +1 -1
  90. package/packages/sprint-planner/package.json +1 -1
  91. package/packages/subscription-engine/package.json +1 -1
  92. package/packages/task-compiler/package.json +1 -1
  93. package/packages/telegram/package.json +1 -1
  94. package/packages/tencentdb-memory/package.json +1 -1
  95. package/packages/tencentdb-sync/package.json +1 -1
  96. package/packages/test-data-generator/package.json +1 -1
  97. package/packages/test-generator/package.json +1 -1
  98. package/packages/todo-bd-sync/package.json +1 -1
  99. package/packages/token-estimation/package.json +1 -1
  100. package/packages/token-optimizer/package.json +1 -1
  101. package/packages/tooling-preference/package.json +1 -1
  102. package/packages/trajectory/package.json +1 -1
  103. package/packages/tui/package.json +1 -1
  104. package/packages/two-phase-review/dist/classify.d.ts +56 -0
  105. package/packages/two-phase-review/dist/classify.d.ts.map +1 -0
  106. package/packages/two-phase-review/dist/classify.js +108 -0
  107. package/packages/two-phase-review/dist/classify.js.map +1 -0
  108. package/packages/two-phase-review/dist/index.d.ts +20 -0
  109. package/packages/two-phase-review/dist/index.d.ts.map +1 -0
  110. package/packages/two-phase-review/dist/index.js +14 -0
  111. package/packages/two-phase-review/dist/index.js.map +1 -0
  112. package/packages/two-phase-review/dist/rules.d.ts +81 -0
  113. package/packages/two-phase-review/dist/rules.d.ts.map +1 -0
  114. package/packages/two-phase-review/dist/rules.js +195 -0
  115. package/packages/two-phase-review/dist/rules.js.map +1 -0
  116. package/packages/two-phase-review/dist/runtime.d.ts +70 -0
  117. package/packages/two-phase-review/dist/runtime.d.ts.map +1 -0
  118. package/packages/two-phase-review/dist/runtime.js +298 -0
  119. package/packages/two-phase-review/dist/runtime.js.map +1 -0
  120. package/packages/two-phase-review/dist/scope.d.ts +68 -0
  121. package/packages/two-phase-review/dist/scope.d.ts.map +1 -0
  122. package/packages/two-phase-review/dist/scope.js +205 -0
  123. package/packages/two-phase-review/dist/scope.js.map +1 -0
  124. package/packages/two-phase-review/dist/signals.d.ts +74 -0
  125. package/packages/two-phase-review/dist/signals.d.ts.map +1 -0
  126. package/packages/two-phase-review/dist/signals.js +297 -0
  127. package/packages/two-phase-review/dist/signals.js.map +1 -0
  128. package/packages/two-phase-review/dist/state.d.ts +72 -0
  129. package/packages/two-phase-review/dist/state.d.ts.map +1 -0
  130. package/packages/two-phase-review/dist/state.js +238 -0
  131. package/packages/two-phase-review/dist/state.js.map +1 -0
  132. package/packages/two-phase-review/dist/types.d.ts +62 -0
  133. package/packages/two-phase-review/dist/types.d.ts.map +1 -0
  134. package/packages/two-phase-review/dist/types.js +9 -0
  135. package/packages/two-phase-review/dist/types.js.map +1 -0
  136. package/packages/two-phase-review/package.json +21 -0
  137. package/packages/two-phase-review/src/classify.ts +129 -0
  138. package/packages/two-phase-review/src/index.ts +110 -0
  139. package/packages/two-phase-review/src/rules.ts +236 -0
  140. package/packages/two-phase-review/src/runtime.ts +392 -0
  141. package/packages/two-phase-review/src/scope.ts +247 -0
  142. package/packages/two-phase-review/src/signals.ts +340 -0
  143. package/packages/two-phase-review/src/state.ts +280 -0
  144. package/packages/two-phase-review/src/types.ts +72 -0
  145. package/packages/two-phase-review/test/classify.test.ts +102 -0
  146. package/packages/two-phase-review/test/helpers.ts +72 -0
  147. package/packages/two-phase-review/test/rules.test.ts +150 -0
  148. package/packages/two-phase-review/test/runtime.test.ts +362 -0
  149. package/packages/two-phase-review/test/scope.test.ts +186 -0
  150. package/packages/two-phase-review/test/signals.test.ts +183 -0
  151. package/packages/two-phase-review/test/state.test.ts +201 -0
  152. package/packages/types/package.json +1 -1
  153. package/packages/voice-api/package.json +1 -1
  154. package/packages/webmcp-tester/package.json +1 -1
  155. package/packages/wiki/package.json +1 -1
  156. package/packages/workflow-events/package.json +1 -1
  157. package/packages/workspace-scanner/package.json +1 -1
  158. package/packages/worktree/dist/worktree.d.ts +31 -0
  159. package/packages/worktree/dist/worktree.d.ts.map +1 -1
  160. package/packages/worktree/dist/worktree.js +21 -8
  161. package/packages/worktree/dist/worktree.js.map +1 -1
  162. package/packages/worktree/package.json +1 -1
  163. package/packages/worktree/src/worktree.ts +49 -8
  164. package/packages/worktree/test/worktree.test.ts +27 -27
  165. package/packages/write-review/package.json +1 -1
  166. package/packages/worktree/worktree.ts +0 -293
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Review signals.
3
+ *
4
+ * A "review now" signal is any attempt to start a comprehensive review while
5
+ * the implementation is still running. The workflow records the signal and
6
+ * defers the review instead of letting it interrupt the implementation.
7
+ */
8
+ import type { ReviewSignal } from "./types.js";
9
+ /**
10
+ * Tool names that start a comprehensive review of the change.
11
+ *
12
+ * Task-level checks (a type error of the file that is edited right now, a
13
+ * failing test of that file) are deliberately absent: they belong to the
14
+ * implementation and stay actionable.
15
+ */
16
+ export declare const DEFAULT_REVIEW_TOOL_PATTERNS: string[];
17
+ /**
18
+ * Command patterns that start a dedicated review runner from a shell.
19
+ *
20
+ * The list is narrow on purpose: a shell command is only a review signal when
21
+ * it runs a review runner, never when it merely mentions one.
22
+ */
23
+ export declare const DEFAULT_REVIEW_COMMAND_PATTERNS: string[];
24
+ /** Read the extra patterns a deployment configured. */
25
+ export declare function parseExtraPatterns(env?: NodeJS.ProcessEnv): string[];
26
+ /**
27
+ * Does the tool name name a comprehensive review?
28
+ *
29
+ * The name is matched exactly: a tool that only contains the name of a
30
+ * review ("read_audit_log") is ordinary work.
31
+ */
32
+ export declare function isComprehensiveReviewTool(toolName: string, extraPatterns?: string[]): boolean;
33
+ /** Does the shell command run a dedicated review runner? */
34
+ export declare function isReviewCommand(command: string): boolean;
35
+ /** The agent name of a generic dispatch tool, when it has one. */
36
+ export declare function dispatchAgentName(toolName: string, input: unknown): string;
37
+ /** A review request that the harness recognized. */
38
+ export interface ReviewInvocation {
39
+ /** The source of the request (tool name, agent name or command). */
40
+ source: string;
41
+ /** The files the request points at (best effort). */
42
+ files: string[];
43
+ /** One short line describing the request. */
44
+ reason: string;
45
+ }
46
+ /** Pull file names out of a tool input (best effort). */
47
+ export declare function extractFiles(toolName: string, input: unknown): string[];
48
+ /**
49
+ * Recognize a request to start a comprehensive review.
50
+ *
51
+ * Returns `null` when the call is an ordinary task-level check.
52
+ */
53
+ export declare function detectReviewInvocation(toolName: string, input: unknown, extraPatterns?: string[]): ReviewInvocation | null;
54
+ /**
55
+ * Did the human ask for a review explicitly?
56
+ *
57
+ * The phase order never overrides the intent of the user: an explicit request
58
+ * runs the review now. A sentence that talks about a review without asking
59
+ * for one is not a request.
60
+ */
61
+ export declare function explicitReviewRequest(message: string): boolean;
62
+ /** The identity of a signal: the same signal is never recorded twice. */
63
+ export declare function signalKey(signal: ReviewSignal): string;
64
+ /** Add a signal, ignoring an identical one. */
65
+ export declare function mergeSignals(signals: ReviewSignal[], signal: ReviewSignal, limit?: number): ReviewSignal[];
66
+ /** The merged view of every recorded signal. */
67
+ export interface SignalSummary {
68
+ sources: string[];
69
+ files: string[];
70
+ reason: string;
71
+ }
72
+ /** Merge the recorded signals into one scope. */
73
+ export declare function summarizeSignals(signals: ReviewSignal[]): SignalSummary;
74
+ //# sourceMappingURL=signals.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signals.d.ts","sourceRoot":"","sources":["../src/signals.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C;;;;;;GAMG;AACH,eAAO,MAAM,4BAA4B,EAAE,MAAM,EAwBhD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,+BAA+B,EAAE,MAAM,EAWnD,CAAC;AA+EF,uDAAuD;AACvD,wBAAgB,kBAAkB,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,MAAM,EAAE,CAOjF;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CACxC,QAAQ,EAAE,MAAM,EAChB,a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review signals.
3
+ *
4
+ * A "review now" signal is any attempt to start a comprehensive review while
5
+ * the implementation is still running. The workflow records the signal and
6
+ * defers the review instead of letting it interrupt the implementation.
7
+ */
8
+ /**
9
+ * Tool names that start a comprehensive review of the change.
10
+ *
11
+ * Task-level checks (a type error of the file that is edited right now, a
12
+ * failing test of that file) are deliberately absent: they belong to the
13
+ * implementation and stay actionable.
14
+ */
15
+ export const DEFAULT_REVIEW_TOOL_PATTERNS = [
16
+ "code-review",
17
+ "code_review",
18
+ "code-reviewer",
19
+ "code_reviewer",
20
+ "differential-review",
21
+ "differential_review",
22
+ "variant-analysis",
23
+ "variant_analysis",
24
+ "fp-check",
25
+ "fp_check",
26
+ "semgrep",
27
+ "codeql",
28
+ "durable-review",
29
+ "durable_review",
30
+ "spec-to-code-compliance",
31
+ "spec_to_code_compliance",
32
+ "security-threat-model",
33
+ "security_threat_model",
34
+ "supply-chain",
35
+ "insecure-defaults",
36
+ "sharp-edges",
37
+ "agentic-actions",
38
+ "audit",
39
+ ];
40
+ /**
41
+ * Command patterns that start a dedicated review runner from a shell.
42
+ *
43
+ * The list is narrow on purpose: a shell command is only a review signal when
44
+ * it runs a review runner, never when it merely mentions one.
45
+ */
46
+ export const DEFAULT_REVIEW_COMMAND_PATTERNS = [
47
+ "code-review",
48
+ "code-reviewer",
49
+ "differential-review",
50
+ "variant-analysis",
51
+ "fp-check",
52
+ "semgrep",
53
+ "codeql",
54
+ "durable-review",
55
+ "security-review",
56
+ "security-reviewer",
57
+ ];
58
+ /** The programs that run another program. */
59
+ const LAUNCHERS = new Set([
60
+ "npx",
61
+ "bunx",
62
+ "bun",
63
+ "pnpm",
64
+ "pnpx",
65
+ "yarn",
66
+ "dlx",
67
+ "uvx",
68
+ "pipx",
69
+ "deno",
70
+ "node",
71
+ "python",
72
+ "python3",
73
+ ]);
74
+ /** The words a launcher uses to name the program it runs. */
75
+ const LAUNCHER_SUBCOMMANDS = new Set(["run", "x", "dlx", "exec"]);
76
+ /** Normalize a name: lower case, spaces and underscores become dashes. */
77
+ function normalizeName(name) {
78
+ return (name ?? "")
79
+ .trim()
80
+ .toLowerCase()
81
+ .replace(/[\s_]+/g, "-");
82
+ }
83
+ /**
84
+ * The candidates of a tool name.
85
+ *
86
+ * A tool is identified by its full name and by the name behind its
87
+ * namespace ("mcp__pi__code-review" is "code-review").
88
+ */
89
+ function toolNameCandidates(name) {
90
+ const raw = (name ?? "").trim();
91
+ if (!raw)
92
+ return [];
93
+ const candidates = new Set();
94
+ const add = (value) => {
95
+ const normalized = normalizeName(value);
96
+ if (normalized)
97
+ candidates.add(normalized);
98
+ };
99
+ add(raw);
100
+ const segments = raw.split(/__|[:/]/).filter(Boolean);
101
+ if (segments.length > 1)
102
+ add(segments[segments.length - 1]);
103
+ return [...candidates];
104
+ }
105
+ /**
106
+ * The program a shell segment runs.
107
+ *
108
+ * Only the program matters: a command that mentions a review runner as an
109
+ * argument ("echo code-review") does not run one.
110
+ */
111
+ function commandExecutable(segment) {
112
+ const tokens = segment.trim().split(/\s+/).filter(Boolean);
113
+ let index = 0;
114
+ while (index < tokens.length && /^[A-Za-z_][A-Za-z0-9_]*=/.test(tokens[index]))
115
+ index += 1;
116
+ while (index < tokens.length &&
117
+ ["sudo", "env", "command", "time", "nohup"].includes(tokens[index].toLowerCase())) {
118
+ index += 1;
119
+ }
120
+ while (index < tokens.length && tokens[index].startsWith("-"))
121
+ index += 1;
122
+ let executable = tokens[index] ?? "";
123
+ if (!executable)
124
+ return "";
125
+ if (LAUNCHERS.has(executable.toLowerCase())) {
126
+ index += 1;
127
+ while (index < tokens.length && tokens[index].startsWith("-"))
128
+ index += 1;
129
+ if (LAUNCHER_SUBCOMMANDS.has((tokens[index] ?? "").toLowerCase()))
130
+ index += 1;
131
+ executable = tokens[index] ?? "";
132
+ }
133
+ const name = executable.split("/").pop() ?? "";
134
+ return normalizeName(name.replace(/\.(js|mjs|cjs|ts|sh)$/, ""));
135
+ }
136
+ /** Read the extra patterns a deployment configured. */
137
+ export function parseExtraPatterns(env = process.env) {
138
+ const raw = env.PI_TWO_PHASE_REVIEW_TOOLS;
139
+ if (!raw)
140
+ return [];
141
+ return raw
142
+ .split(",")
143
+ .map((entry) => entry.trim().toLowerCase())
144
+ .filter(Boolean);
145
+ }
146
+ /**
147
+ * Does the tool name name a comprehensive review?
148
+ *
149
+ * The name is matched exactly: a tool that only contains the name of a
150
+ * review ("read_audit_log") is ordinary work.
151
+ */
152
+ export function isComprehensiveReviewTool(toolName, extraPatterns = []) {
153
+ const candidates = toolNameCandidates(toolName);
154
+ if (candidates.length === 0)
155
+ return false;
156
+ const patterns = [...DEFAULT_REVIEW_TOOL_PATTERNS, ...extraPatterns].map(normalizeName);
157
+ return candidates.some((candidate) => patterns.includes(candidate));
158
+ }
159
+ /** Does the shell command run a dedicated review runner? */
160
+ export function isReviewCommand(command) {
161
+ const text = (command ?? "").toLowerCase();
162
+ if (!text)
163
+ return false;
164
+ const runners = new Set(DEFAULT_REVIEW_COMMAND_PATTERNS.map(normalizeName));
165
+ const segments = text.split(/(?:\|\||&&|[;\n|])/);
166
+ return segments.some((segment) => {
167
+ const executable = commandExecutable(segment);
168
+ return executable !== "" && runners.has(executable);
169
+ });
170
+ }
171
+ /** The agent name of a generic dispatch tool, when it has one. */
172
+ export function dispatchAgentName(toolName, input) {
173
+ if (!["subagent", "task", "dispatch_agent"].includes(toolName))
174
+ return "";
175
+ const args = (input ?? {});
176
+ const candidates = [args.agent, args.subagent_type, args.agentName, args.role];
177
+ for (const candidate of candidates) {
178
+ if (typeof candidate === "string" && candidate.trim())
179
+ return candidate.trim();
180
+ }
181
+ return "";
182
+ }
183
+ const SOURCE_FILE_PATTERN = /(?:^|[\s"'`(=])((?:\.{0,2}\/)?(?:[\w.@+-]+\/)*[\w.@+-]+\.(?:ts|tsx|mts|cts|js|jsx|mjs|cjs))/g;
184
+ /** Pull file names out of a tool input (best effort). */
185
+ export function extractFiles(toolName, input) {
186
+ const args = (input ?? {});
187
+ const files = new Set();
188
+ const add = (value) => {
189
+ if (typeof value === "string" && value.trim())
190
+ files.add(value.trim());
191
+ };
192
+ const addList = (value) => {
193
+ if (Array.isArray(value)) {
194
+ for (const entry of value)
195
+ add(entry);
196
+ return;
197
+ }
198
+ add(value);
199
+ };
200
+ for (const key of ["files", "paths", "path", "file", "target", "targets", "scope"]) {
201
+ addList(args[key]);
202
+ }
203
+ if (toolName === "bash" && typeof args.command === "string") {
204
+ const matches = args.command.matchAll(SOURCE_FILE_PATTERN);
205
+ for (const match of matches) {
206
+ if (match[1])
207
+ files.add(match[1]);
208
+ }
209
+ }
210
+ return [...files].slice(0, 200);
211
+ }
212
+ /**
213
+ * Recognize a request to start a comprehensive review.
214
+ *
215
+ * Returns `null` when the call is an ordinary task-level check.
216
+ */
217
+ export function detectReviewInvocation(toolName, input, extraPatterns = []) {
218
+ if (isComprehensiveReviewTool(toolName, extraPatterns)) {
219
+ return {
220
+ source: toolName,
221
+ files: extractFiles(toolName, input),
222
+ reason: `a comprehensive review was requested with ${toolName}`,
223
+ };
224
+ }
225
+ const agent = dispatchAgentName(toolName, input);
226
+ if (agent && isComprehensiveReviewTool(agent, extraPatterns)) {
227
+ return {
228
+ source: agent,
229
+ files: extractFiles(toolName, input),
230
+ reason: `a comprehensive review was requested with the ${agent} reviewer`,
231
+ };
232
+ }
233
+ if (toolName === "bash") {
234
+ const command = input?.command;
235
+ if (typeof command === "string" && isReviewCommand(command)) {
236
+ return {
237
+ source: "bash",
238
+ files: extractFiles(toolName, input),
239
+ reason: `a review runner was started: ${command.trim().slice(0, 160)}`,
240
+ };
241
+ }
242
+ }
243
+ return null;
244
+ }
245
+ /**
246
+ * A negation of a review request.
247
+ *
248
+ * The negation is read per sentence, so "do not review yet" does not silence
249
+ * a later "please review the diff".
250
+ */
251
+ const NEGATED_REVIEW = /\b(?:do not|don'?t|does not|doesn'?t|no|without|skip|avoid|postpone|defer|later|not yet|never)\b[^.!?\n]{0,40}\b(?:review|audit)\b/i;
252
+ /** The ways a human asks for a review. */
253
+ const AFFIRMATIVE_REVIEW = [
254
+ /\b(?:please\s+)?(?:run|do|perform|start|begin|execute|launch|carry out|give)\s+(?:a\s+|an\s+|the\s+)?(?:comprehensive\s+|full\s+|complete\s+|code\s+|security\s+)?(?:review|audit)\b/i,
255
+ /\b(?:can|could|would|will|shall)\s+you\s+(?:please\s+)?(?:review|audit)\b/i,
256
+ /\b(?:review|audit)\s+(?:the|this|that|my|our|it|everything|all|each)\b/i,
257
+ /^\s*(?:please\s+)?(?:review|audit)\b/i,
258
+ /\b(?:review|audit)\s+(?:now|again)\b/i,
259
+ ];
260
+ /**
261
+ * Did the human ask for a review explicitly?
262
+ *
263
+ * The phase order never overrides the intent of the user: an explicit request
264
+ * runs the review now. A sentence that talks about a review without asking
265
+ * for one is not a request.
266
+ */
267
+ export function explicitReviewRequest(message) {
268
+ if (!message)
269
+ return false;
270
+ const sentences = message.split(/(?<=[.!?])\s+/);
271
+ return sentences.some((sentence) => {
272
+ if (NEGATED_REVIEW.test(sentence))
273
+ return false;
274
+ return AFFIRMATIVE_REVIEW.some((pattern) => pattern.test(sentence));
275
+ });
276
+ }
277
+ /** The identity of a signal: the same signal is never recorded twice. */
278
+ export function signalKey(signal) {
279
+ const files = [...signal.files].sort().join(",");
280
+ return `${signal.source}::${files}::${signal.reason.trim().toLowerCase()}`;
281
+ }
282
+ /** Add a signal, ignoring an identical one. */
283
+ export function mergeSignals(signals, signal, limit = 50) {
284
+ const key = signalKey(signal);
285
+ if (signals.some((entry) => signalKey(entry) === key))
286
+ return signals;
287
+ const next = [...signals, signal];
288
+ return next.length > limit ? next.slice(next.length - limit) : next;
289
+ }
290
+ /** Merge the recorded signals into one scope. */
291
+ export function summarizeSignals(signals) {
292
+ const sources = [...new Set(signals.map((signal) => signal.source))];
293
+ const files = [...new Set(signals.flatMap((signal) => signal.files))];
294
+ const reason = [...new Set(signals.map((signal) => signal.reason.trim()).filter(Boolean))].join("; ");
295
+ return { sources, files, reason };
296
+ }
297
+ //# sourceMappingURL=signals.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signals.js","sourceRoot":"","sources":["../src/signals.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAa;IACrD,aAAa;IACb,aAAa;IACb,eAAe;IACf,eAAe;IACf,qBAAqB;IACrB,qBAAqB;IACrB,kBAAkB;IAClB,kBAAkB;IAClB,UAAU;IACV,UAAU;IACV,SAAS;IACT,QAAQ;IACR,gBAAgB;IAChB,gBAAgB;IAChB,yBAAyB;IACzB,yBAAyB;IACzB,uBAAuB;IACvB,uBAAuB;IACvB,cAAc;IACd,mBAAmB;IACnB,aAAa;IACb,iBAAiB;IACjB,OAAO;CACP,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,+BAA+B,GAAa;IACxD,aAAa;IACb,eAAe;IACf,qBAAqB;IACrB,kBAAkB;IAClB,UAAU;IACV,SAAS;IACT,QAAQ;IACR,gBAAgB;IAChB,iBAAiB;IACjB,mBAAmB;CACnB,CAAC;AAEF,6CAA6C;AAC7C,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC;IACzB,KAAK;IACL,MAAM;IACN,KAAK;IACL,MAAM;IACN,MAAM;IACN,MAAM;IACN,KAAK;IACL,KAAK;IACL,MAAM;IACN,MAAM;IACN,MAAM;IACN,QAAQ;IACR,SAAS;CACT,CAAC,CAAC;AAEH,6DAA6D;AAC7D,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;AAElE,0EAA0E;AAC1E,SAAS,aAAa,CAAC,IAAY;IAClC,OAAO,CAAC,IAAI,IAAI,EAAE,CAAC;SACjB,IAAI,EAAE;SACN,WAAW,EAAE;SACb,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;AAC3B,CAAC;AAED;;;;;GAKG;AACH,SAAS,kBAAk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flow.
3
+ *
4
+ * The state survives a restart and a compaction, so the phase, the task start
5
+ * revision, the review scope, the finished chunks and the open findings are
6
+ * never lost.
7
+ */
8
+ import type { ReviewChunk, ReviewFinding, ReviewSignal, TwoPhasePhase, TwoPhaseState } from "./types.js";
9
+ /** The directory the state files live in. */
10
+ export declare const TWO_PHASE_STATE_DIR: string;
11
+ /** A fresh state for a task. */
12
+ export declare function createState(taskId: string, startRevision?: string | null): TwoPhaseState;
13
+ /** Make a file name safe for the file system. */
14
+ export declare function safeFileName(taskId: string): string;
15
+ /** Repair a state that was read from disk. */
16
+ export declare function normalizeState(value: unknown, taskId: string): TwoPhaseState;
17
+ /** The state of one task on disk. */
18
+ export declare class TwoPhaseStateStore {
19
+ private readonly dir;
20
+ constructor(dir?: string);
21
+ /** The file the state of the task lives in. */
22
+ path(taskId: string): string;
23
+ /**
24
+ * Read the state of the task.
25
+ *
26
+ * `null` means that there is no state. A state that exists but cannot be
27
+ * read is an error: it must not be mistaken for a fresh task, because that
28
+ * would lose the revision the task started at and the progress of the
29
+ * review.
30
+ */
31
+ read(taskId: string): TwoPhaseState | null;
32
+ /**
33
+ * Write the state of the task.
34
+ *
35
+ * A failing write is reported to the caller: the runtime decides whether
36
+ * the session may continue without the state, the test sees the reason.
37
+ */
38
+ write(state: TwoPhaseState): TwoPhaseState;
39
+ /** Remove the state of the task. */
40
+ clear(taskId: string): void;
41
+ }
42
+ /** Move to a phase, never backwards. */
43
+ export declare function moveToPhase(state: TwoPhaseState, phase: TwoPhasePhase): TwoPhaseState;
44
+ /** Record a review signal. The phase does not change. */
45
+ export declare function recordSignal(state: TwoPhaseState, signal: ReviewSignal): TwoPhaseState;
46
+ /** The implementation is done: the review waits for its scope. */
47
+ export declare function transitionToReviewPending(state: TwoPhaseState, scopeFiles: string[]): TwoPhaseState;
48
+ /** The review starts with the given chunks. */
49
+ export declare function startReview(state: TwoPhaseState, chunks: ReviewChunk[]): TwoPhaseState;
50
+ /** Mark a review chunk as finished. */
51
+ export declare function markChunkDone(state: TwoPhaseState, chunkId: string): TwoPhaseState;
52
+ /** Record a confirmed finding. */
53
+ export declare function recordFinding(state: TwoPhaseState, finding: ReviewFinding): TwoPhaseState;
54
+ /**
55
+ * The review found something: the fixes are now the work.
56
+ *
57
+ * The fixes start when the review is finished: a fix phase before the review
58
+ * ran would hide the work that is still open.
59
+ */
60
+ export declare function transitionToReviewFixes(state: TwoPhaseState): TwoPhaseState;
61
+ /** Every chunk is finished. */
62
+ export declare function allChunksDone(state: TwoPhaseState): boolean;
63
+ /**
64
+ * The work is finished.
65
+ *
66
+ * The task is only complete when the review ran over every chunk. The
67
+ * implementation phase never completes the task on its own.
68
+ */
69
+ export declare function markComplete(state: TwoPhaseState): TwoPhaseState;
70
+ /** Is a review queued? */
71
+ export declare function hasQueuedReview(state: TwoPhaseState): boolean;
72
+ //# sourceMappingURL=state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,OAAO,KAAK,EACX,WAAW,EACX,aAAa,EACb,YAAY,EACZ,aAAa,EACb,aAAa,EACb,MAAM,YAAY,CAAC;AAEpB,6CAA6C;AAC7C,eAAO,MAAM,mBAAmB,QAI/B,CAAC;AAaF,gCAAgC;AAChC,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,aAAa,GAAE,MAAM,GAAG,IAAW,GAAG,aAAa,CAW9F;AAED,iDAAiD;AACjD,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEnD;AAkBD,8CAA8C;AAC9C,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,aAAa,CAgB5E;AAkCD,qCAAqC;AACrC,qBAAa,kBAAkB;IAClB,OAAO,CAAC,QAAQ,CAAC,GAAG;IAAhC,YAA6B,GAAG,GAAE,MAA4B,EAAI;IAElE,+CAA+C;IAC/C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