@rhei-team/rhei 1.0.0-beta.0
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.
- package/README.md +1048 -0
- package/bin/rhei-mcp.js +3 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +86366 -0
- package/dist/premium/contracts.d.ts +445 -0
- package/dist/premium/contracts.js +97 -0
- package/dist/vendor/rhei-core/briefs.js +1276 -0
- package/dist/vendor/rhei-core/codeAgent.js +615 -0
- package/dist/vendor/rhei-core/codeEditSession.js +293 -0
- package/dist/vendor/rhei-core/codeIntelligence.js +4287 -0
- package/dist/vendor/rhei-core/codeMarket.js +8946 -0
- package/dist/vendor/rhei-core/codeReviewIntelligence.js +5918 -0
- package/dist/vendor/rhei-core/codeSemantics.js +172427 -0
- package/dist/vendor/rhei-core/codeStory.js +667 -0
- package/dist/vendor/rhei-core/codeStrategyPlan.js +663 -0
- package/dist/vendor/rhei-core/codeTrail.js +2781 -0
- package/dist/vendor/rhei-core/codeWorkHandoff.js +281 -0
- package/dist/vendor/rhei-core/contextQuery.js +1119 -0
- package/dist/vendor/rhei-core/contextRouting.js +2052 -0
- package/dist/vendor/rhei-core/evidenceLedger.js +5336 -0
- package/dist/vendor/rhei-core/executionSafety.js +0 -0
- package/dist/vendor/rhei-core/goalIntelligence.js +2218 -0
- package/dist/vendor/rhei-core/model-lanes.js +75 -0
- package/dist/vendor/rhei-core/now.js +127 -0
- package/dist/vendor/rhei-core/package.json +29 -0
- package/dist/vendor/rhei-core/programPlan.js +3153 -0
- package/dist/vendor/rhei-core/search.js +196 -0
- package/dist/vendor/rhei-core/serviceIntelligence.js +1734 -0
- package/dist/vendor/rhei-core/workflowPlan.js +1660 -0
- package/package.json +41 -0
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
// ../core/src/codeWorkHandoff/types.ts
|
|
2
|
+
var CODE_WORK_HANDOFF_SCHEMA_VERSION = 1;
|
|
3
|
+
var CODE_WORK_HANDOFF_KIND = "code_work_handoff";
|
|
4
|
+
var CODE_WORK_HANDOFF_TOKEN_ESTIMATE_VERSION = "char-div-4-v1";
|
|
5
|
+
// ../core/src/codeWorkHandoff/builders.ts
|
|
6
|
+
function defaultGeneratedAt() {
|
|
7
|
+
return Date.now();
|
|
8
|
+
}
|
|
9
|
+
var REPORT_ONLY_GUARDRAILS = {
|
|
10
|
+
reportOnly: true,
|
|
11
|
+
advisoryOnly: true,
|
|
12
|
+
noAuthority: true,
|
|
13
|
+
noProviderCalls: true,
|
|
14
|
+
noNetworkCalls: true,
|
|
15
|
+
noFilesystemSourceScan: true,
|
|
16
|
+
noSessionMutation: true,
|
|
17
|
+
noWrites: true,
|
|
18
|
+
applyRequiresSeparateGatedTool: true
|
|
19
|
+
};
|
|
20
|
+
function buildCodeWorkHandoffV1(args) {
|
|
21
|
+
const generatedAt = args.generatedAt ?? defaultGeneratedAt();
|
|
22
|
+
const handoffId = args.handoffId ?? `code-work-handoff:${stableSlug(args.workflowPlan.workflowPlanId)}`;
|
|
23
|
+
const sessionId = args.sessionId ?? args.strategyPlan?.sourceRefs.sessionId;
|
|
24
|
+
const workflowFeedback = args.workflowOracleFeedback ?? [];
|
|
25
|
+
const requiredQuestionSummary = summarizeRequiredQuestions(args.workflowPlan.oraclePromptPackets, workflowFeedback);
|
|
26
|
+
const serviceConnectionIds = uniqueStrings([
|
|
27
|
+
...args.workflowPlan.sourceRefs.serviceConnectionIds ?? [],
|
|
28
|
+
...args.strategyPlan?.sourceRefs.serviceConnectionIds ?? [],
|
|
29
|
+
...(args.serviceConnectionRefs ?? []).map((ref) => ref.serviceConnectionId)
|
|
30
|
+
]);
|
|
31
|
+
const serviceEvidenceRefs = uniqueStrings([
|
|
32
|
+
...(args.serviceConnectionRefs ?? []).flatMap((ref) => [ref.evidenceRef, ref.contractRef]),
|
|
33
|
+
...args.workflowPlan.serviceConnectionGates.flatMap((gate) => gate.evidenceRefs)
|
|
34
|
+
]);
|
|
35
|
+
const receiptRefs = uniqueStrings([
|
|
36
|
+
...args.receiptRefs ?? [],
|
|
37
|
+
...args.workflowPlan.receipts.map((receipt) => receipt.receiptId)
|
|
38
|
+
]);
|
|
39
|
+
const contextRefs = {
|
|
40
|
+
exactRefs: args.workflowPlan.sessionSelect.exactRefs,
|
|
41
|
+
sourceRefs: resolveSourceRefs(args),
|
|
42
|
+
evidenceRefs: resolveEvidenceRefs(args, serviceEvidenceRefs),
|
|
43
|
+
receiptRefs,
|
|
44
|
+
avoidRefs: args.workflowPlan.sessionSelect.avoidRefs,
|
|
45
|
+
pathOnlyRefs: args.workflowPlan.sessionSelect.pathOnlyRefs,
|
|
46
|
+
deferredRefs: args.workflowPlan.sessionSelect.deferredRefs,
|
|
47
|
+
readSliceIds: args.workflowPlan.sessionSelect.readSlices.map((slice) => slice.readSliceId)
|
|
48
|
+
};
|
|
49
|
+
const blockingBeforeWriteGateIds = uniqueStrings([
|
|
50
|
+
...args.workflowPlan.gates.filter((gate) => gate.blockingBeforeWrite).map((gate) => gate.gateId),
|
|
51
|
+
...args.workflowPlan.synapseGates.filter((gate) => gate.blockingBeforeWrite).map((gate) => gate.gateId),
|
|
52
|
+
...args.workflowPlan.serviceConnectionGates.filter((gate) => gate.blockingBeforeWrite).map((gate) => gate.gateId)
|
|
53
|
+
]);
|
|
54
|
+
const nextAction = selectCodeWorkNextAction({
|
|
55
|
+
serviceGateIdsNeedingEvidence: args.workflowPlan.serviceConnectionGates.filter((gate) => gate.status !== "satisfied_by_input").map((gate) => gate.gateId),
|
|
56
|
+
unansweredRequiredQuestionIds: requiredQuestionSummary.unansweredRequiredQuestionIds,
|
|
57
|
+
failedRequiredQuestionIds: requiredQuestionSummary.failedRequiredQuestionIds,
|
|
58
|
+
sessionId,
|
|
59
|
+
requiredReadSliceIds: contextRefs.readSliceIds,
|
|
60
|
+
completedReadSliceIds: args.completedReadSliceIds ?? []
|
|
61
|
+
});
|
|
62
|
+
return {
|
|
63
|
+
schemaVersion: CODE_WORK_HANDOFF_SCHEMA_VERSION,
|
|
64
|
+
kind: CODE_WORK_HANDOFF_KIND,
|
|
65
|
+
handoffId,
|
|
66
|
+
generatedAt,
|
|
67
|
+
objective: args.objective ?? args.workflowPlan.objective ?? args.strategyPlan?.objective ?? "Code work handoff",
|
|
68
|
+
sourceRefs: {
|
|
69
|
+
strategyId: args.strategyPlan?.strategyId ?? args.workflowPlan.sourceRefs.strategyId,
|
|
70
|
+
workflowPlanId: args.workflowPlan.workflowPlanId,
|
|
71
|
+
contextPacketIds: uniqueStrings([
|
|
72
|
+
...args.workflowPlan.sourceRefs.contextPacketIds,
|
|
73
|
+
...args.strategyPlan?.sourceRefs.contextPacketIds ?? []
|
|
74
|
+
]),
|
|
75
|
+
workstreamPacketIds: uniqueStrings(args.strategyPlan?.sourceRefs.workstreamPacketIds ?? []),
|
|
76
|
+
sessionId,
|
|
77
|
+
serviceConnectionIds
|
|
78
|
+
},
|
|
79
|
+
contextRefs,
|
|
80
|
+
workflowPlan: args.workflowPlan,
|
|
81
|
+
oracle: {
|
|
82
|
+
promptPackets: args.workflowPlan.oraclePromptPackets,
|
|
83
|
+
strategyOracleFeedback: args.strategyOracleFeedback ?? args.strategyPlan?.oracleFeedback ?? [],
|
|
84
|
+
workflowOracleFeedback: workflowFeedback,
|
|
85
|
+
unansweredRequiredQuestionIds: requiredQuestionSummary.unansweredRequiredQuestionIds,
|
|
86
|
+
failedRequiredQuestionIds: requiredQuestionSummary.failedRequiredQuestionIds,
|
|
87
|
+
allRequiredQuestionsAnswered: requiredQuestionSummary.unansweredRequiredQuestionIds.length === 0 && requiredQuestionSummary.failedRequiredQuestionIds.length === 0
|
|
88
|
+
},
|
|
89
|
+
gates: {
|
|
90
|
+
workflowGates: args.workflowPlan.gates,
|
|
91
|
+
synapseGates: args.workflowPlan.synapseGates,
|
|
92
|
+
serviceConnectionGates: args.workflowPlan.serviceConnectionGates,
|
|
93
|
+
blockingBeforeWriteGateIds
|
|
94
|
+
},
|
|
95
|
+
budgets: {
|
|
96
|
+
estimateVersion: CODE_WORK_HANDOFF_TOKEN_ESTIMATE_VERSION,
|
|
97
|
+
sessionSelect: args.workflowPlan.sessionSelect.tokenBudget,
|
|
98
|
+
workflowTokenSummary: args.workflowPlan.tokenSummary
|
|
99
|
+
},
|
|
100
|
+
serviceConnections: {
|
|
101
|
+
ids: serviceConnectionIds,
|
|
102
|
+
refs: args.serviceConnectionRefs ?? [],
|
|
103
|
+
evidenceRefs: serviceEvidenceRefs,
|
|
104
|
+
gateIds: args.workflowPlan.serviceConnectionGates.map((gate) => gate.gateId)
|
|
105
|
+
},
|
|
106
|
+
receipts: {
|
|
107
|
+
refs: receiptRefs,
|
|
108
|
+
expected: args.workflowPlan.receipts,
|
|
109
|
+
requiredBeforeApply: receiptRefs
|
|
110
|
+
},
|
|
111
|
+
delegation: {
|
|
112
|
+
editAgentBriefs: buildEditAgentDelegationBriefs({
|
|
113
|
+
handoffId,
|
|
114
|
+
workflowPlanId: args.workflowPlan.workflowPlanId,
|
|
115
|
+
workflowSteps: args.workflowPlan.workflowSteps,
|
|
116
|
+
readSlices: args.workflowPlan.sessionSelect.readSlices,
|
|
117
|
+
serviceConnectionGates: args.workflowPlan.serviceConnectionGates,
|
|
118
|
+
serviceConnectionIds
|
|
119
|
+
})
|
|
120
|
+
},
|
|
121
|
+
nextAction,
|
|
122
|
+
warnings: uniqueStrings([
|
|
123
|
+
...args.warnings ?? [],
|
|
124
|
+
...args.workflowPlan.warnings,
|
|
125
|
+
...(args.strategyPlan?.warnings ?? []).map((warning) => `strategy:${warning}`)
|
|
126
|
+
]),
|
|
127
|
+
guardrails: REPORT_ONLY_GUARDRAILS
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
function summarizeRequiredQuestions(packets, feedback) {
|
|
131
|
+
const unansweredRequiredQuestionIds = [];
|
|
132
|
+
const failedRequiredQuestionIds = [];
|
|
133
|
+
for (const packet of packets) {
|
|
134
|
+
for (const question of packet.questions.filter((item) => item.requiredBeforeWrite)) {
|
|
135
|
+
const answer = feedback.find((item) => feedbackMatchesQuestion(item, packet.packetId, question.questionId, question.questionKind));
|
|
136
|
+
if (!answer) {
|
|
137
|
+
unansweredRequiredQuestionIds.push(question.questionId);
|
|
138
|
+
} else if (!answer.answer) {
|
|
139
|
+
failedRequiredQuestionIds.push(question.questionId);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return {
|
|
144
|
+
unansweredRequiredQuestionIds: uniqueStrings(unansweredRequiredQuestionIds),
|
|
145
|
+
failedRequiredQuestionIds: uniqueStrings(failedRequiredQuestionIds)
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
function feedbackMatchesQuestion(feedback, packetId, questionId, questionKind) {
|
|
149
|
+
if (feedback.packetId && feedback.packetId !== packetId)
|
|
150
|
+
return false;
|
|
151
|
+
if (feedback.questionId)
|
|
152
|
+
return feedback.questionId === questionId;
|
|
153
|
+
if (feedback.answer)
|
|
154
|
+
return false;
|
|
155
|
+
return feedback.questionKind === questionKind;
|
|
156
|
+
}
|
|
157
|
+
function selectCodeWorkNextAction(args) {
|
|
158
|
+
if (args.serviceGateIdsNeedingEvidence.length > 0) {
|
|
159
|
+
return nextAction({
|
|
160
|
+
kind: "provide_service_connection_evidence",
|
|
161
|
+
targetTool: "rhei_code_prepare_work",
|
|
162
|
+
reason: "One or more service connection gates still need compact IDs or external evidence before edit planning.",
|
|
163
|
+
blockingGateIds: args.serviceGateIdsNeedingEvidence
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
if (args.failedRequiredQuestionIds.length > 0) {
|
|
167
|
+
return nextAction({
|
|
168
|
+
kind: "revise_context_or_scope",
|
|
169
|
+
reason: "A required workflow oracle question was answered false, so context or scope should be revised before edit planning.",
|
|
170
|
+
requiredQuestionIds: args.failedRequiredQuestionIds
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
if (args.unansweredRequiredQuestionIds.length > 0) {
|
|
174
|
+
return nextAction({
|
|
175
|
+
kind: "answer_oracle_prompt_packets",
|
|
176
|
+
reason: "Required workflow oracle prompt-packet questions must be answered before edit planning.",
|
|
177
|
+
requiredQuestionIds: args.unansweredRequiredQuestionIds
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
if (!args.sessionId) {
|
|
181
|
+
return nextAction({
|
|
182
|
+
kind: "start_code_session_from_handoff",
|
|
183
|
+
targetTool: "rhei_code_session_start",
|
|
184
|
+
reason: "No Code Session ID is attached; start a bounded Code Session from this report-only handoff."
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
const completed = new Set(args.completedReadSliceIds);
|
|
188
|
+
const unread = args.requiredReadSliceIds.filter((readSliceId) => !completed.has(readSliceId));
|
|
189
|
+
if (unread.length > 0) {
|
|
190
|
+
return nextAction({
|
|
191
|
+
kind: "read_session_select_slices",
|
|
192
|
+
targetTool: "rhei_code_read",
|
|
193
|
+
reason: "Read the selected session slices before preparing any bounded edit proposal.",
|
|
194
|
+
requiredReadSliceIds: unread
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
return nextAction({
|
|
198
|
+
kind: "plan_edits_with_handoff",
|
|
199
|
+
targetTool: "rhei_code_plan_edits",
|
|
200
|
+
reason: "All required report-only gates available to this handoff are satisfied; prepare an edit proposal through a separate planning tool, not apply."
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
function nextAction(args) {
|
|
204
|
+
return {
|
|
205
|
+
...args,
|
|
206
|
+
availableNow: false,
|
|
207
|
+
reportOnly: true,
|
|
208
|
+
advisoryOnly: true,
|
|
209
|
+
noAuthority: true
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
function resolveSourceRefs(args) {
|
|
213
|
+
if (!args.strategyPlan)
|
|
214
|
+
return args.workflowPlan.sessionSelect.exactRefs;
|
|
215
|
+
return uniqueStrings(args.strategyPlan.connectedFileGroups.filter((group) => ["source", "config"].includes(group.role)).flatMap((group) => group.paths));
|
|
216
|
+
}
|
|
217
|
+
function resolveEvidenceRefs(args, serviceEvidenceRefs) {
|
|
218
|
+
const strategyEvidenceRefs = args.strategyPlan?.connectedFileGroups.filter((group) => ["test", "doc", "service_connection_evidence"].includes(group.role)).flatMap((group) => group.paths) ?? [];
|
|
219
|
+
return uniqueStrings([
|
|
220
|
+
...strategyEvidenceRefs,
|
|
221
|
+
...serviceEvidenceRefs,
|
|
222
|
+
...args.workflowPlan.serviceConnectionGates.flatMap((gate) => gate.evidenceRefs)
|
|
223
|
+
]);
|
|
224
|
+
}
|
|
225
|
+
function buildEditAgentDelegationBriefs(args) {
|
|
226
|
+
const slicesById = new Map(args.readSlices.map((slice) => [slice.readSliceId, slice]));
|
|
227
|
+
const serviceConnectionIdsByGateId = new Map(args.serviceConnectionGates.map((gate) => [gate.gateId, gate.serviceConnectionId]));
|
|
228
|
+
return args.workflowSteps.map((step) => {
|
|
229
|
+
const stepSlices = step.requiredReadSliceIds.map((readSliceId) => slicesById.get(readSliceId)).filter(isDefined);
|
|
230
|
+
const stepServiceConnectionIds = uniqueStrings([
|
|
231
|
+
...step.gateIds.map((gateId) => serviceConnectionIdsByGateId.get(gateId)),
|
|
232
|
+
...stepSlices.flatMap((slice) => slice.serviceConnectionGateIds.map((gateId) => serviceConnectionIdsByGateId.get(gateId)))
|
|
233
|
+
]);
|
|
234
|
+
return {
|
|
235
|
+
briefId: `edit-brief:${stableSlug(args.handoffId)}:${stableSlug(step.stepId)}`,
|
|
236
|
+
handoffId: args.handoffId,
|
|
237
|
+
workflowPlanId: args.workflowPlanId,
|
|
238
|
+
stepId: step.stepId,
|
|
239
|
+
title: step.title,
|
|
240
|
+
purpose: step.purpose,
|
|
241
|
+
exactRefs: uniqueStrings(stepSlices.map((slice) => slice.path)),
|
|
242
|
+
requiredReadSliceIds: step.requiredReadSliceIds,
|
|
243
|
+
editableRefs: uniqueStrings(stepSlices.filter((slice) => slice.role === "edit").map((slice) => slice.path)),
|
|
244
|
+
validationRefs: uniqueStrings(stepSlices.filter((slice) => ["test", "doc"].includes(slice.role)).map((slice) => slice.path)),
|
|
245
|
+
serviceConnectionIds: stepServiceConnectionIds.length > 0 ? stepServiceConnectionIds : args.serviceConnectionIds,
|
|
246
|
+
requiredGateIds: step.gateIds,
|
|
247
|
+
instructions: [
|
|
248
|
+
"Use this brief as report-only context; it grants no write authority.",
|
|
249
|
+
"Read only the requiredReadSliceIds/exactRefs before proposing changes.",
|
|
250
|
+
"Do not apply changes from this handoff; apply remains a separate gated tool path."
|
|
251
|
+
],
|
|
252
|
+
reportOnly: true,
|
|
253
|
+
advisoryOnly: true,
|
|
254
|
+
noAuthority: true
|
|
255
|
+
};
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
function isDefined(value) {
|
|
259
|
+
return value !== undefined;
|
|
260
|
+
}
|
|
261
|
+
function stableSlug(value) {
|
|
262
|
+
return value.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "").slice(0, 96) || "handoff";
|
|
263
|
+
}
|
|
264
|
+
function uniqueStrings(values) {
|
|
265
|
+
const output = [];
|
|
266
|
+
const seen = new Set;
|
|
267
|
+
for (const value of values) {
|
|
268
|
+
const text = typeof value === "string" ? value.trim() : "";
|
|
269
|
+
if (!text || seen.has(text))
|
|
270
|
+
continue;
|
|
271
|
+
seen.add(text);
|
|
272
|
+
output.push(text);
|
|
273
|
+
}
|
|
274
|
+
return output;
|
|
275
|
+
}
|
|
276
|
+
export {
|
|
277
|
+
buildCodeWorkHandoffV1,
|
|
278
|
+
CODE_WORK_HANDOFF_TOKEN_ESTIMATE_VERSION,
|
|
279
|
+
CODE_WORK_HANDOFF_SCHEMA_VERSION,
|
|
280
|
+
CODE_WORK_HANDOFF_KIND
|
|
281
|
+
};
|