pi-harness-runtime 1.1.451 → 1.1.452

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 (93) hide show
  1. package/AGENTS.md +53 -0
  2. package/CHANGELOG.md +24 -0
  3. package/index.ts +172 -21
  4. package/package.json +1 -1
  5. package/packages/agent-policy/package.json +1 -1
  6. package/packages/auth/package.json +1 -1
  7. package/packages/autonomous-runtime/package.json +1 -1
  8. package/packages/checkpoint/package.json +1 -1
  9. package/packages/clipboard/package.json +1 -1
  10. package/packages/codex-watcher/package.json +1 -1
  11. package/packages/config-capture/package.json +1 -1
  12. package/packages/contracts/package.json +1 -1
  13. package/packages/cookie-sanitizer/package.json +1 -1
  14. package/packages/evaluation-engine/package.json +1 -1
  15. package/packages/event-bus/package.json +1 -1
  16. package/packages/event-store/package.json +1 -1
  17. package/packages/experience-replay/package.json +1 -1
  18. package/packages/file-copy-helper/package.json +1 -1
  19. package/packages/intent-analyzer/package.json +1 -1
  20. package/packages/jev-judge/dist/continuation-status.d.ts +31 -0
  21. package/packages/jev-judge/dist/continuation-status.d.ts.map +1 -0
  22. package/packages/jev-judge/dist/continuation-status.js +40 -0
  23. package/packages/jev-judge/dist/continuation-status.js.map +1 -0
  24. package/packages/jev-judge/dist/delegation-harness.d.ts +74 -1
  25. package/packages/jev-judge/dist/delegation-harness.d.ts.map +1 -1
  26. package/packages/jev-judge/dist/delegation-harness.js +183 -18
  27. package/packages/jev-judge/dist/delegation-harness.js.map +1 -1
  28. package/packages/jev-judge/dist/delegation-scope.d.ts +88 -0
  29. package/packages/jev-judge/dist/delegation-scope.d.ts.map +1 -0
  30. package/packages/jev-judge/dist/delegation-scope.js +218 -0
  31. package/packages/jev-judge/dist/delegation-scope.js.map +1 -0
  32. package/packages/jev-judge/package.json +1 -1
  33. package/packages/jev-judge/src/continuation-status.ts +41 -0
  34. package/packages/jev-judge/src/delegation-harness.ts +254 -45
  35. package/packages/jev-judge/src/delegation-scope.ts +264 -0
  36. package/packages/knowledge-retrieval/package.json +1 -1
  37. package/packages/learning-engine/package.json +1 -1
  38. package/packages/logging/package.json +1 -1
  39. package/packages/memory-engine/package.json +1 -1
  40. package/packages/notification/package.json +1 -1
  41. package/packages/paperclip-integration/package.json +1 -1
  42. package/packages/performance-optimizer/package.json +1 -1
  43. package/packages/privilege-broker/package.json +1 -1
  44. package/packages/prompt-compiler/package.json +1 -1
  45. package/packages/providers/package.json +1 -1
  46. package/packages/qdrant-skills/package.json +1 -1
  47. package/packages/quota-manager/package.json +1 -1
  48. package/packages/relay/package.json +1 -1
  49. package/packages/skill-mcp-client/package.json +1 -1
  50. package/packages/skills/package.json +1 -1
  51. package/packages/todo-bd-sync/package.json +1 -1
  52. package/packages/token-estimation/package.json +1 -1
  53. package/packages/tooling-preference/package.json +1 -1
  54. package/packages/trajectory/package.json +1 -1
  55. package/packages/tui/package.json +1 -1
  56. package/packages/two-phase-review/dist/classify.d.ts +22 -1
  57. package/packages/two-phase-review/dist/classify.d.ts.map +1 -1
  58. package/packages/two-phase-review/dist/classify.js +37 -1
  59. package/packages/two-phase-review/dist/classify.js.map +1 -1
  60. package/packages/two-phase-review/dist/index.d.ts +4 -2
  61. package/packages/two-phase-review/dist/index.d.ts.map +1 -1
  62. package/packages/two-phase-review/dist/index.js +3 -2
  63. package/packages/two-phase-review/dist/index.js.map +1 -1
  64. package/packages/two-phase-review/dist/rules.d.ts +8 -3
  65. package/packages/two-phase-review/dist/rules.d.ts.map +1 -1
  66. package/packages/two-phase-review/dist/rules.js +36 -5
  67. package/packages/two-phase-review/dist/rules.js.map +1 -1
  68. package/packages/two-phase-review/dist/runtime.d.ts +9 -0
  69. package/packages/two-phase-review/dist/runtime.d.ts.map +1 -1
  70. package/packages/two-phase-review/dist/runtime.js +68 -17
  71. package/packages/two-phase-review/dist/runtime.js.map +1 -1
  72. package/packages/two-phase-review/dist/state.d.ts +15 -0
  73. package/packages/two-phase-review/dist/state.d.ts.map +1 -1
  74. package/packages/two-phase-review/dist/state.js +37 -2
  75. package/packages/two-phase-review/dist/state.js.map +1 -1
  76. package/packages/two-phase-review/dist/types.d.ts +2 -2
  77. package/packages/two-phase-review/dist/types.d.ts.map +1 -1
  78. package/packages/two-phase-review/dist/validation.d.ts +50 -0
  79. package/packages/two-phase-review/dist/validation.d.ts.map +1 -0
  80. package/packages/two-phase-review/dist/validation.js +54 -0
  81. package/packages/two-phase-review/dist/validation.js.map +1 -0
  82. package/packages/two-phase-review/package.json +1 -1
  83. package/packages/two-phase-review/src/classify.ts +38 -1
  84. package/packages/two-phase-review/src/index.ts +16 -0
  85. package/packages/two-phase-review/src/rules.ts +48 -4
  86. package/packages/two-phase-review/src/runtime.ts +88 -17
  87. package/packages/two-phase-review/src/state.ts +38 -2
  88. package/packages/two-phase-review/src/types.ts +2 -1
  89. package/packages/two-phase-review/src/validation.ts +86 -0
  90. package/packages/types/package.json +1 -1
  91. package/packages/webmcp-tester/package.json +1 -1
  92. package/packages/wiki/package.json +1 -1
  93. package/packages/write-review/package.json +1 -1
@@ -5,15 +5,32 @@
5
5
  * Uses inline types to avoid cross-package dependency.
6
6
  */
7
7
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
8
+ import type { ScopeMeasurement, ScopeWorkGroup } from "./delegation-scope.js";
8
9
  /**
9
10
  * Extension capability for delegation (inline to avoid dependency)
10
11
  */
11
12
  export interface ExtensionCapability {
12
13
  name: string;
14
+ /** The tool that can dispatch a child. */
15
+ toolName: string;
13
16
  supportsSubagents: boolean;
17
+ /**
18
+ * The schema of the tool carries a parameter that isolates the work of
19
+ * a child. Without such a parameter the claim is not made.
20
+ */
14
21
  supportsWorkIsolation: boolean;
22
+ /**
23
+ * The schema of the tool carries a parameter that stops a child. Without
24
+ * such a parameter the claim is not made.
25
+ */
15
26
  supportsCancellation: boolean;
16
27
  availableTools: string[];
28
+ /**
29
+ * The schema of the tool was read and the tool is active.
30
+ *
31
+ * This is not a proof that a child ever ran: it says that the session
32
+ * can ask for one. Only a dispatch that was really sent proves that.
33
+ */
17
34
  verified: boolean;
18
35
  }
19
36
  /**
@@ -26,10 +43,28 @@ export type DelegationStrategy = "delegate" | "script_then_delegate" | "script_o
26
43
  export interface DelegationDecision {
27
44
  strategy: DelegationStrategy;
28
45
  reason: string;
29
- workGroups: unknown[];
46
+ /**
47
+ * The groups the work falls into. They are empty unless the scope was
48
+ * measured: a decision without groups is not a delegation plan.
49
+ */
50
+ workGroups: ScopeWorkGroup[];
30
51
  validationExpectations: string;
31
52
  confidence: "high" | "medium" | "low";
32
53
  jevUsed: boolean;
54
+ /**
55
+ * Whether a child was really dispatched.
56
+ *
57
+ * The harness assesses the work, it does not run it: the agent is the
58
+ * one that sends the groups to the sub-agent tool.
59
+ */
60
+ dispatched: boolean;
61
+ /**
62
+ * The name of the active tool that can dispatch a child.
63
+ *
64
+ * It is empty when no such tool is active. The name is the proof that
65
+ * the dispatch is possible, not the proof that it happened.
66
+ */
67
+ dispatchTool?: string;
33
68
  reassessmentTriggers: string[];
34
69
  }
35
70
  /**
@@ -46,6 +81,11 @@ export interface ScopeFacts {
46
81
  isComplex: boolean;
47
82
  fileTypes: Record<string, number>;
48
83
  fingerprint: string;
84
+ /**
85
+ * The measured groups of the work. A delegation decision needs them:
86
+ * without groups there is nothing to hand to a child.
87
+ */
88
+ workGroups: ScopeWorkGroup[];
49
89
  }
50
90
  /**
51
91
  * Delegation receipt
@@ -72,6 +112,39 @@ export interface DelegationHarnessConfig {
72
112
  minCallSites?: number;
73
113
  minComponents?: number;
74
114
  }
115
+ /**
116
+ * Build the scope facts from a measurement.
117
+ *
118
+ * Every number is a count of something the measurement found. The
119
+ * estimate is the size of the workspace: it is a real number, and it says
120
+ * how much of the repository the measured files are.
121
+ */
122
+ export declare function scopeFactsFromMeasurement(measurement: ScopeMeasurement): ScopeFacts;
123
+ /**
124
+ * Build the message that hands a delegation plan to the agent.
125
+ *
126
+ * The message names the measured groups and the tool that can dispatch a
127
+ * child. It does not claim that anything was dispatched: the harness
128
+ * measured the work, the agent is the one that sends the groups out.
129
+ *
130
+ * @param decision The decision of the assessment.
131
+ * @returns The message, or null when there is nothing to hand out.
132
+ */
133
+ export declare function buildDelegationSteer(decision: {
134
+ strategy: string;
135
+ workGroups?: {
136
+ id: string;
137
+ files: string[];
138
+ }[];
139
+ dispatchTool?: string;
140
+ } | null): string | null;
141
+ /**
142
+ * The property names of a tool schema.
143
+ *
144
+ * A schema is a plain object: the properties of the object, of every
145
+ * branch of a union, and of every item of an array.
146
+ */
147
+ export declare function schemaPropertyNames(schema: unknown): Set<string>;
75
148
  /**
76
149
  * Create delegation harness integration
77
150
  */
@@ -1 +1 @@
1
- {"version":3,"file":"delegation-harness.d.ts","sourceRoot":"","sources":["../src/delegation-harness.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAIpE;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,iBAAiB,EAAE,OAAO,CAAC;IAC3B,qBAAqB,EAAE,OAAO,CAAC;IAC/B,oBAAoB,EAAE,OAAO,CAAC;IAC9B,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAC1B,UAAU,GACV,sBAAsB,GACtB,aAAa,GACb,cAAc,GACd,aAAa,CAAC;AAElB;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,OAAO,EAAE,CAAC;IACtB,sBAAsB,EAAE,MAAM,CAAC;IAC/B,UAAU,EAAE,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC;IACtC,OAAO,EAAE,OAAO,CAAC;IACjB,oBAAoB,EAAE,MAAM,EAAE,CAAC;CAChC;AAED;;GAEG;AACH,MAAM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AC;QAAC,KAAK,EAAE,MAAM,EAAE,CAAA;KAAE,EAAE,CAAC;IAC/C,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GAAG,IAAI,GACP,MAAM,GAAG,IAAI,CAmBf;AAyBD;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,OAAO,GAAG,GAAG,CAAC,MAAM,CAAC,CAoBhE;AASD;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,EAAE,EAAE,YAAY,EAChB,MAAM,GAAE,uBAA4B;8BAoBC,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC;0BA+C3C,UAAU,KAAG,OAAO;oBA6ExC,UAAU,gBACH,MAAM,KACnB,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;;;;EAiDtC;AAED,MAAM,MAAM,iBAAiB,GAAG,UAAU,CAAC,OAAO,uBAAuB,CAAC,CAAC"}
@@ -56,9 +56,139 @@ function hasReceipt(workspacePath, taskId) {
56
56
  return existsSync(getReceiptPath(workspacePath, taskId));
57
57
  }
58
58
  /**
59
- * Sub-agent tool names
59
+ * The number of groups that can be handed to children at once.
60
+ *
61
+ * More groups than that is not a delegation plan: it is a list of files
62
+ * that still needs a decision about the order.
63
+ */
64
+ const MAX_DELEGATED_GROUPS = 8;
65
+ /**
66
+ * Build the scope facts from a measurement.
67
+ *
68
+ * Every number is a count of something the measurement found. The
69
+ * estimate is the size of the workspace: it is a real number, and it says
70
+ * how much of the repository the measured files are.
71
+ */
72
+ export function scopeFactsFromMeasurement(measurement) {
73
+ const groups = measurement.groups;
74
+ const extensions = Object.keys(measurement.fileTypes);
75
+ return {
76
+ estimatedFiles: measurement.workspaceFiles,
77
+ observedFiles: measurement.files.length,
78
+ estimatedCallSites: measurement.callSites,
79
+ observedCallSites: measurement.callSites,
80
+ independentComponents: groups.length,
81
+ tightlyCoupled: groups.length <= 1,
82
+ // A mechanical change touches one kind of file, and there is more
83
+ // than one of them: a rename across many files is mechanical, a
84
+ // single file is just work.
85
+ isMechanical: extensions.length === 1 && measurement.files.length >= 3,
86
+ // A complex change spans more than one module.
87
+ isComplex: groups.length > 1,
88
+ fileTypes: measurement.fileTypes,
89
+ fingerprint: measurement.fingerprint,
90
+ workGroups: groups,
91
+ };
92
+ }
93
+ /**
94
+ * The reason why the work stays in the session.
95
+ */
96
+ function singleAgentReason(groups) {
97
+ if (groups.length === 1) {
98
+ return `One measured group (${groups[0].id}): the work stays in this session`;
99
+ }
100
+ if (groups.length > MAX_DELEGATED_GROUPS) {
101
+ return `${groups.length} measured groups: too many to hand out at once, the work stays in this session`;
102
+ }
103
+ return "No measured group of work: the work stays in this session";
104
+ }
105
+ /**
106
+ * Build the message that hands a delegation plan to the agent.
107
+ *
108
+ * The message names the measured groups and the tool that can dispatch a
109
+ * child. It does not claim that anything was dispatched: the harness
110
+ * measured the work, the agent is the one that sends the groups out.
111
+ *
112
+ * @param decision The decision of the assessment.
113
+ * @returns The message, or null when there is nothing to hand out.
60
114
  */
61
- const SUBAGENT_TOOLS = ["subagent", "spawn", "delegate", "run_subagent"];
115
+ export function buildDelegationSteer(decision) {
116
+ if (!decision)
117
+ return null;
118
+ if (decision.strategy !== "delegate")
119
+ return null;
120
+ const groups = decision.workGroups ?? [];
121
+ if (groups.length === 0)
122
+ return null;
123
+ const lines = [
124
+ `[Delegation plan] The measured scope of this request falls into ${groups.length} independent group(s):`,
125
+ ...groups.map((group) => `- ${group.id} (${group.files.length} file(s))`),
126
+ ];
127
+ if (decision.dispatchTool) {
128
+ lines.push(`Send each group to a child agent with the ${decision.dispatchTool} tool, then integrate the results and validate them.`);
129
+ }
130
+ else {
131
+ lines.push("Send each group to a child agent, then integrate the results and validate them.");
132
+ }
133
+ lines.push("The harness measured the scope; it did not dispatch the groups itself.");
134
+ return lines.join("\n");
135
+ }
136
+ /**
137
+ * The parameters of a tool that dispatch a child.
138
+ *
139
+ * A tool that takes the task of a child can dispatch one. The name of the
140
+ * tool says nothing about that: only the schema does.
141
+ */
142
+ const DISPATCH_PARAMETERS = ["task", "prompt", "instructions", "description"];
143
+ /**
144
+ * The parameters of a tool that isolate the work of a child.
145
+ */
146
+ const ISOLATION_PARAMETERS = ["cwd", "worktree", "isolation", "sandbox", "branch"];
147
+ /**
148
+ * The parameters of a tool that stop a child.
149
+ */
150
+ const CANCELLATION_PARAMETERS = ["timeout", "timeoutMs", "cancel", "signal", "abort"];
151
+ /**
152
+ * The words that name a child agent.
153
+ */
154
+ const CHILD_WORDS = ["subagent", "sub-agent", "child agent", "delegate", "spawn"];
155
+ /**
156
+ * The property names of a tool schema.
157
+ *
158
+ * A schema is a plain object: the properties of the object, of every
159
+ * branch of a union, and of every item of an array.
160
+ */
161
+ export function schemaPropertyNames(schema) {
162
+ const names = new Set();
163
+ const visit = (node) => {
164
+ if (!node || typeof node !== "object")
165
+ return;
166
+ const record = node;
167
+ const properties = record.properties;
168
+ if (properties && typeof properties === "object") {
169
+ for (const name of Object.keys(properties)) {
170
+ names.add(name);
171
+ }
172
+ }
173
+ for (const branch of ["anyOf", "oneOf", "allOf"]) {
174
+ const list = record[branch];
175
+ if (Array.isArray(list))
176
+ for (const entry of list)
177
+ visit(entry);
178
+ }
179
+ const items = record.items;
180
+ if (items)
181
+ visit(items);
182
+ };
183
+ visit(schema);
184
+ return names;
185
+ }
186
+ /**
187
+ * The text of a tool that names what the tool is for.
188
+ */
189
+ function toolText(tool) {
190
+ return `${tool.name ?? ""} ${tool.description ?? ""}`.toLowerCase();
191
+ }
62
192
  /**
63
193
  * Create delegation harness integration
64
194
  */
@@ -73,23 +203,41 @@ export function createDelegationHarness(pi, config = {}) {
73
203
  const minComponents = config.minComponents ?? 2;
74
204
  /**
75
205
  * Discover and cache delegation capability
206
+ *
207
+ * The capability is read from the schema of the tools, not from their
208
+ * names: a tool that carries the task of a child can dispatch one, and
209
+ * only a schema that carries a working directory or a timeout proves
210
+ * that the work can be isolated or stopped.
76
211
  */
77
212
  async function discoverCapability() {
78
213
  if (state.capability)
79
214
  return state.capability;
80
215
  try {
81
216
  const allTools = pi.getAllTools();
82
- const toolNames = allTools.map((t) => t.name);
83
- const activeTools = pi.getActiveTools();
84
- const hasSubagentTool = SUBAGENT_TOOLS.some((tool) => toolNames.includes(tool) || activeTools.includes(tool));
85
- if (hasSubagentTool) {
217
+ const activeTools = new Set(pi.getActiveTools());
218
+ for (const tool of allTools) {
219
+ const properties = schemaPropertyNames(tool.parameters);
220
+ const dispatches = DISPATCH_PARAMETERS.some((parameter) => properties.has(parameter));
221
+ if (!dispatches)
222
+ continue;
223
+ // The tool has to be about a child agent: a schema that takes a
224
+ // task is not enough when the tool is something else entirely.
225
+ const text = toolText(tool);
226
+ if (!CHILD_WORDS.some((word) => text.includes(word)))
227
+ continue;
228
+ const isolation = ISOLATION_PARAMETERS.find((parameter) => properties.has(parameter));
229
+ const cancellation = CANCELLATION_PARAMETERS.find((parameter) => properties.has(parameter));
230
+ const isActive = activeTools.has(tool.name);
86
231
  state.capability = {
87
- name: "subagent-extension",
232
+ name: tool.name,
233
+ toolName: tool.name,
88
234
  supportsSubagents: true,
89
- supportsWorkIsolation: true,
90
- supportsCancellation: true,
91
- availableTools: activeTools.filter((t) => SUBAGENT_TOOLS.some((st) => t.includes(st))),
92
- verified: true,
235
+ supportsWorkIsolation: isolation !== undefined,
236
+ supportsCancellation: cancellation !== undefined,
237
+ availableTools: isActive ? [tool.name] : [],
238
+ // The capability is verified when the tool is active: an inactive
239
+ // tool cannot dispatch anything.
240
+ verified: isActive,
93
241
  };
94
242
  return state.capability;
95
243
  }
@@ -101,8 +249,14 @@ export function createDelegationHarness(pi, config = {}) {
101
249
  }
102
250
  /**
103
251
  * Check if delegation assessment should be triggered
252
+ *
253
+ * The thresholds are compared with the measured scope. A scope that was
254
+ * not measured is never assessed: an empty measurement is not a small
255
+ * task, it is an unknown one.
104
256
  */
105
257
  function shouldAssess(facts) {
258
+ if (facts.observedFiles <= 0)
259
+ return false;
106
260
  if (facts.observedFiles >= minFiles)
107
261
  return true;
108
262
  if (facts.observedCallSites >= minCallSites)
@@ -113,48 +267,59 @@ export function createDelegationHarness(pi, config = {}) {
113
267
  }
114
268
  /**
115
269
  * Make deterministic assessment
270
+ *
271
+ * The decision is built from the measured scope and from the schema of
272
+ * the tools. A strategy that claims a delegation needs the groups of the
273
+ * measurement: without them there is nothing to hand to a child.
116
274
  */
117
275
  function makeDeterministicAssessment(facts, capability) {
118
276
  if (!capability?.verified) {
119
277
  return {
120
278
  strategy: "unavailable",
121
- reason: "No verified sub-agent capability",
279
+ reason: "No active tool can dispatch a child agent",
122
280
  workGroups: [],
123
281
  validationExpectations: "Parent handles validation",
124
282
  confidence: "high",
125
283
  jevUsed: false,
284
+ dispatched: false,
126
285
  reassessmentTriggers: ["Extension available"],
127
286
  };
128
287
  }
129
288
  if (facts.isMechanical && !facts.isComplex) {
130
289
  return {
131
290
  strategy: "script_only",
132
- reason: "Mechanical transformation",
291
+ reason: `Mechanical transformation of ${facts.observedFiles} measured file(s)`,
133
292
  workGroups: [],
134
293
  validationExpectations: "Script output validation",
135
294
  confidence: "high",
136
295
  jevUsed: false,
296
+ dispatched: false,
137
297
  reassessmentTriggers: ["Transformation unreliable"],
138
298
  };
139
299
  }
140
- if (facts.independentComponents >= 2 && !facts.tightlyCoupled) {
300
+ const groups = facts.workGroups ?? [];
301
+ if (groups.length >= 2 && groups.length <= MAX_DELEGATED_GROUPS && !facts.tightlyCoupled) {
141
302
  return {
142
303
  strategy: "delegate",
143
- reason: `${facts.independentComponents} independent components`,
144
- workGroups: [],
304
+ reason: `${groups.length} measured groups over ${facts.observedFiles} file(s); the agent dispatches the groups`,
305
+ workGroups: groups,
145
306
  validationExpectations: "Each group validated, then integrated",
146
307
  confidence: "medium",
147
308
  jevUsed: false,
309
+ // The harness measured the groups, it did not dispatch them.
310
+ dispatched: false,
311
+ dispatchTool: capability.toolName,
148
312
  reassessmentTriggers: ["Scope expands", "Coupling discovered"],
149
313
  };
150
314
  }
151
315
  return {
152
316
  strategy: "single_agent",
153
- reason: "Default to single agent",
154
- workGroups: [],
317
+ reason: singleAgentReason(groups),
318
+ workGroups: groups,
155
319
  validationExpectations: "Parent validates",
156
320
  confidence: "low",
157
321
  jevUsed: false,
322
+ dispatched: false,
158
323
  reassessmentTriggers: ["Scope exceeds threshold"],
159
324
  };
160
325
  }
@@ -1 +1 @@
1
- {"version":3,"file":"delegation-harness.js","sourceRoot":"","sources":["../src/delegation-harness.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,SAAS,CAAC;AAE/C,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AACxE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAuE5B;;GAEG;AACH,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,SAAS,EAAE,EAAE,qBAAqB,EAAE,kBAAkB,CAAC,CAAC;AAEnG;;GAEG;AACH,SAAS,cAAc;IACrB,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;QAC3B,SAAS,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC5C,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAS,cAAc,CAAC,aAAqB,EAAE,MAAc;IAC3D,MAAM,QAAQ,GAAG,aAAa,CAAC,OAAO,CAAC,iBAAiB,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC;IAC3E,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,iBAAiB,EAAE,GAAG,CAAC,CAAC;IACxD,OAAO,IAAI,CAAC,SAAS,EAAE,GAAG,QAAQ,KAAK,QAAQ,OAAO,CAAC,CAAC;AAC1D,CAAC;AAED;;GAEG;AACH,SAAS,WAAW,CAAC,OAA0B;IAC7C,cAAc,EAAE,CAAC;IACj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"}
@@ -0,0 +1,88 @@
1
+ /**
2
+ * The measured scope of a task.
3
+ *
4
+ * A delegation decision is only worth something when it is based on the
5
+ * work that really has to be done. The numbers of a request are not a
6
+ * measurement: "refactor everything" says nothing about how many files
7
+ * are affected. This module measures the scope in the workspace:
8
+ *
9
+ * - The files of the workspace that the request actually names.
10
+ * - The files the session has already changed.
11
+ * - The groups those files form (one group per package or directory).
12
+ * - The tracked files that reference the measured groups.
13
+ *
14
+ * Every number in the result is a count of something real. When nothing
15
+ * can be measured the result is empty, and the caller has to say so
16
+ * instead of inventing a scope.
17
+ */
18
+ /** One group of files that can be worked on together. */
19
+ export interface ScopeWorkGroup {
20
+ /** The name of the group: the package or the directory of the files. */
21
+ id: string;
22
+ /** The files of the group. */
23
+ files: string[];
24
+ }
25
+ /** The measured scope of a task. */
26
+ export interface ScopeMeasurement {
27
+ /** The files the measurement found. */
28
+ files: string[];
29
+ /** The groups the files form. */
30
+ groups: ScopeWorkGroup[];
31
+ /** The number of tracked files of the workspace. */
32
+ workspaceFiles: number;
33
+ /** The number of tracked files that reference the measured groups. */
34
+ callSites: number;
35
+ /** The histogram of the file extensions. */
36
+ fileTypes: Record<string, number>;
37
+ /** A stable fingerprint of the measurement. */
38
+ fingerprint: string;
39
+ /** The hints of the request that matched a file of the workspace. */
40
+ matchedHints: string[];
41
+ /** How the files were found: the request named them, or the session changed them. */
42
+ source: "request" | "working-tree" | "none";
43
+ }
44
+ /** The options of {@link measureScope}. */
45
+ export interface MeasureScopeOptions {
46
+ /** The root of the workspace. */
47
+ workspacePath: string;
48
+ /** The path fragments of the request, for example a package name. */
49
+ hints?: string[];
50
+ /** The files the session has changed in the workspace. */
51
+ changedFiles?: string[];
52
+ /** The upper bound of the files of one measurement. */
53
+ limit?: number;
54
+ }
55
+ /**
56
+ * The files the working tree has changed.
57
+ */
58
+ export declare function changedFiles(workspacePath: string): string[];
59
+ /**
60
+ * The group a file belongs to: its package, or its top directory.
61
+ */
62
+ export declare function moduleOf(file: string): string;
63
+ /**
64
+ * The extension of a file, without the dot.
65
+ */
66
+ export declare function extensionOf(file: string): string;
67
+ /**
68
+ * Group the measured files.
69
+ */
70
+ export declare function groupFiles(files: string[]): ScopeWorkGroup[];
71
+ /**
72
+ * A stable fingerprint of a set of files.
73
+ */
74
+ export declare function fingerprintOf(files: string[]): string;
75
+ /**
76
+ * The path fragments of a request.
77
+ *
78
+ * A hint is a place in the repository that the request names: a path with
79
+ * a separator, or a file name with a known extension. The measurement
80
+ * checks every hint against the tracked files, so a hint that names
81
+ * nothing is simply not used.
82
+ */
83
+ export declare function scopeHintsFromText(text: string): string[];
84
+ /**
85
+ * Measure the scope of a task in the workspace.
86
+ */
87
+ export declare function measureScope(options: MeasureScopeOptions): ScopeMeasurement;
88
+ //# sourceMappingURL=delegation-scope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delegation-scope.d.ts","sourceRoot":"","sources":["../src/delegation-scope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAKH,yDAAyD;AACzD,MAAM,WAAW,cAAc;IAC9B,wEAAwE;IACxE,EAAE,EAAE,MAAM,CAAC;IACX,8BAA8B;IAC9B,KAAK,EAAE,MAAM,EAAE,CAAC;CAChB;AAED,oCAAoC;AACpC,MAAM,WAAW,gBAAgB;IAChC,uCAAuC;IACvC,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,iCAAiC;IACjC,MAAM,EAAE,cAAc,EAAE,CAAC;IACzB,oDAAoD;IACpD,cAAc,EAAE,MAAM,CAAC;IACvB,sEAAsE;IACtE,SAAS,EAAE,MAAM,CAAC;IAClB,4CAA4C;IAC5C,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,+CAA+C;IAC/C,WAAW,EAAE,MAAM,CAAC;IACpB,qEAAqE;IACrE,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,qFAAqF;IACrF,MAAM,EAAE,SAAS,GAAG,cAAc,GAAG,MA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