@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,293 @@
|
|
|
1
|
+
// ../core/src/codeEditSession/index.ts
|
|
2
|
+
var AGENT_EDIT_SESSION_CONTRACT_VERSION = "agent_edit_session_v1";
|
|
3
|
+
var AGENT_EDIT_SESSION_SCHEMA_VERSION = 1;
|
|
4
|
+
var AGENT_EDIT_EXECUTION_POLICY_VERSION = "agent_edit_execution_policy_v1";
|
|
5
|
+
function buildAgentEditSessionHandoffV1(args) {
|
|
6
|
+
const createdAt = args.createdAt ?? Date.now();
|
|
7
|
+
const reasonCodes = uniqueStrings([
|
|
8
|
+
...args.policy.localToCloud.reasonCodes,
|
|
9
|
+
...args.reasonCodes ?? []
|
|
10
|
+
]);
|
|
11
|
+
return {
|
|
12
|
+
schemaVersion: AGENT_EDIT_SESSION_SCHEMA_VERSION,
|
|
13
|
+
contractVersion: AGENT_EDIT_SESSION_CONTRACT_VERSION,
|
|
14
|
+
handoffId: `agent-edit-handoff:${args.sourceSessionId}:${createdAt.toString(36)}`,
|
|
15
|
+
sourceSessionId: args.sourceSessionId,
|
|
16
|
+
editSessionId: args.editSessionId,
|
|
17
|
+
projectId: args.projectId,
|
|
18
|
+
repoId: args.repoId,
|
|
19
|
+
targetRunner: args.policy.localToCloud.target,
|
|
20
|
+
editCommands: args.editCommands ?? buildDefaultModalEditCommands(args.policy.localToCloud.carry.validationCommand),
|
|
21
|
+
workroomRunId: args.workroomRunId,
|
|
22
|
+
synapseReceiptRef: args.synapseReceiptRef,
|
|
23
|
+
synapseWaiverRef: args.synapseWaiverRef,
|
|
24
|
+
validationTrust: args.validationTrust,
|
|
25
|
+
carry: {
|
|
26
|
+
allowedPaths: args.policy.localToCloud.carry.allowedPaths,
|
|
27
|
+
deniedPaths: args.policy.localToCloud.carry.deniedPaths,
|
|
28
|
+
validationCommand: args.policy.localToCloud.carry.validationCommand,
|
|
29
|
+
baselineRequired: true,
|
|
30
|
+
receiptBoundContext: true,
|
|
31
|
+
baseline: args.baseline,
|
|
32
|
+
contextRefs: uniqueStrings(args.contextRefs ?? []),
|
|
33
|
+
diagnosticEvidence: uniqueStrings(args.diagnosticEvidence ?? []),
|
|
34
|
+
prompt: args.prompt,
|
|
35
|
+
maxAttempts: args.maxAttempts,
|
|
36
|
+
sourceRepoPath: args.sourceRepoPath
|
|
37
|
+
},
|
|
38
|
+
reasonCodes,
|
|
39
|
+
battleProofRefs: uniqueStrings(args.battleProofRefs ?? []),
|
|
40
|
+
createdAt,
|
|
41
|
+
noAuthority: true
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function buildDefaultModalEditCommands(validationCommand) {
|
|
45
|
+
const commands = [{
|
|
46
|
+
schemaVersion: AGENT_EDIT_SESSION_SCHEMA_VERSION,
|
|
47
|
+
commandKind: "edit",
|
|
48
|
+
runner: "opencode_run_json",
|
|
49
|
+
command: "opencode run --format json",
|
|
50
|
+
argv: ["opencode", "run", "--format", "json"],
|
|
51
|
+
runAfter: "dispatch",
|
|
52
|
+
maxRuns: 1,
|
|
53
|
+
sandboxOnly: true,
|
|
54
|
+
noCanonicalApply: true
|
|
55
|
+
}];
|
|
56
|
+
if (validationCommand) {
|
|
57
|
+
commands.push({
|
|
58
|
+
schemaVersion: AGENT_EDIT_SESSION_SCHEMA_VERSION,
|
|
59
|
+
commandKind: "validation",
|
|
60
|
+
runner: "shell",
|
|
61
|
+
command: validationCommand,
|
|
62
|
+
runAfter: "edit",
|
|
63
|
+
maxRuns: 1,
|
|
64
|
+
sandboxOnly: true,
|
|
65
|
+
noCanonicalApply: true
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
return commands;
|
|
69
|
+
}
|
|
70
|
+
function mapAgentEditOutcomeToExecutionReceiptStatus(outcome) {
|
|
71
|
+
if (outcome === "fixed")
|
|
72
|
+
return "succeeded";
|
|
73
|
+
if (outcome === "still_failing")
|
|
74
|
+
return "failed";
|
|
75
|
+
return "blocked";
|
|
76
|
+
}
|
|
77
|
+
function isAgentEditExecutionModeV1(value) {
|
|
78
|
+
return value === "sandboxed" || value === "scoped" || value === "yolo";
|
|
79
|
+
}
|
|
80
|
+
function isAgentEditCallerContextV1(value) {
|
|
81
|
+
return typeof value === "string" && [
|
|
82
|
+
"local_cli",
|
|
83
|
+
"local_app",
|
|
84
|
+
"web_app",
|
|
85
|
+
"cloud_worker",
|
|
86
|
+
"pr_review_local",
|
|
87
|
+
"pr_review_cloud",
|
|
88
|
+
"review_local",
|
|
89
|
+
"review_cloud",
|
|
90
|
+
"api",
|
|
91
|
+
"unknown"
|
|
92
|
+
].includes(value);
|
|
93
|
+
}
|
|
94
|
+
function isAgentEditWorkspaceKindV1(value) {
|
|
95
|
+
return typeof value === "string" && [
|
|
96
|
+
"local_worktree",
|
|
97
|
+
"modal_sandbox",
|
|
98
|
+
"cloud_ephemeral",
|
|
99
|
+
"provider_sandbox",
|
|
100
|
+
"unknown"
|
|
101
|
+
].includes(value);
|
|
102
|
+
}
|
|
103
|
+
function resolveAgentEditExecutionPolicyV1(args = {}) {
|
|
104
|
+
const callerContext = args.callerContext ?? "unknown";
|
|
105
|
+
const workspaceKind = args.workspaceKind ?? defaultWorkspaceKind(callerContext);
|
|
106
|
+
const requestedMode = normalizeRequestedMode(args.requestedMode) ?? defaultModeForContext(callerContext, workspaceKind);
|
|
107
|
+
const reviewLike = isReviewLikeContext(callerContext);
|
|
108
|
+
const cloudLike = isCloudLikeContext(callerContext, workspaceKind);
|
|
109
|
+
const localLike = isLocalLikeContext(callerContext, workspaceKind);
|
|
110
|
+
const yoloRequested = requestedMode === "yolo";
|
|
111
|
+
const yoloAllowed = yoloRequested && args.allowYolo === true && (!cloudLike && !reviewLike || args.environmentAllowsYolo === true);
|
|
112
|
+
const effectiveMode = yoloAllowed ? "yolo" : requestedMode === "scoped" && !cloudLike && !reviewLike ? "scoped" : defaultModeForContext(callerContext, workspaceKind);
|
|
113
|
+
const deniedPaths = uniqueStrings(args.deniedPaths ?? []);
|
|
114
|
+
const allowedPaths = uniqueStrings(args.allowedPaths ?? []);
|
|
115
|
+
const runnerKind = args.runnerKind ?? defaultRunnerKind(workspaceKind, callerContext);
|
|
116
|
+
const editEngine = args.editEngine ?? (runnerKind === "modal" ? "opencode_run_json" : "rhei_code_session");
|
|
117
|
+
const providerKind = args.providerKind ?? "workpool";
|
|
118
|
+
const yoloReasonCodes = uniqueStrings([
|
|
119
|
+
yoloRequested ? "yolo:requested" : undefined,
|
|
120
|
+
yoloRequested && args.allowYolo !== true ? "yolo:missing_explicit_allow" : undefined,
|
|
121
|
+
yoloRequested && (cloudLike || reviewLike) && args.environmentAllowsYolo !== true ? "yolo:blocked_for_cloud_or_review_without_environment_allow" : undefined,
|
|
122
|
+
yoloAllowed ? "yolo:allowed_outside_allowed_paths" : undefined
|
|
123
|
+
]);
|
|
124
|
+
const localToCloud = resolveLocalToCloudPolicy({
|
|
125
|
+
...args,
|
|
126
|
+
callerContext,
|
|
127
|
+
workspaceKind,
|
|
128
|
+
allowedPaths,
|
|
129
|
+
deniedPaths,
|
|
130
|
+
yoloDenied: yoloRequested && !yoloAllowed
|
|
131
|
+
});
|
|
132
|
+
const reasonCodes = uniqueStrings([
|
|
133
|
+
`caller:${callerContext}`,
|
|
134
|
+
`workspace:${workspaceKind}`,
|
|
135
|
+
`requested_mode:${requestedMode}`,
|
|
136
|
+
`effective_mode:${effectiveMode}`,
|
|
137
|
+
reviewLike ? "policy:review_defaults_to_sandbox" : undefined,
|
|
138
|
+
cloudLike ? "policy:cloud_defaults_to_sandbox" : undefined,
|
|
139
|
+
localLike && effectiveMode === "scoped" ? "policy:local_coding_scoped" : undefined,
|
|
140
|
+
localToCloud.recommended ? "policy:local_to_cloud_available" : undefined,
|
|
141
|
+
...yoloReasonCodes
|
|
142
|
+
]);
|
|
143
|
+
return {
|
|
144
|
+
schemaVersion: AGENT_EDIT_SESSION_SCHEMA_VERSION,
|
|
145
|
+
policyVersion: AGENT_EDIT_EXECUTION_POLICY_VERSION,
|
|
146
|
+
requestedMode,
|
|
147
|
+
effectiveMode,
|
|
148
|
+
callerContext,
|
|
149
|
+
workspaceKind,
|
|
150
|
+
runnerKind,
|
|
151
|
+
editEngine,
|
|
152
|
+
providerKind,
|
|
153
|
+
pathPolicy: {
|
|
154
|
+
allowedPaths,
|
|
155
|
+
deniedPaths,
|
|
156
|
+
allowOutsideAllowedPaths: effectiveMode === "yolo",
|
|
157
|
+
deniedPathsAlwaysBlock: true
|
|
158
|
+
},
|
|
159
|
+
authority: {
|
|
160
|
+
sandboxMutationAllowed: effectiveMode === "sandboxed" || effectiveMode === "yolo" || runnerKind === "modal",
|
|
161
|
+
canonicalApplyRequiresWriteArbitration: true,
|
|
162
|
+
sourceApplyAuthority: args.sourceApplyAuthority ?? "none",
|
|
163
|
+
autoApply: false,
|
|
164
|
+
autoPush: false,
|
|
165
|
+
autoPrComment: false,
|
|
166
|
+
memoryPromotion: false
|
|
167
|
+
},
|
|
168
|
+
yolo: {
|
|
169
|
+
requested: yoloRequested,
|
|
170
|
+
allowed: yoloAllowed,
|
|
171
|
+
reasonCodes: yoloReasonCodes,
|
|
172
|
+
requiresExplicitOptIn: true,
|
|
173
|
+
neverBypassesDeniedPaths: true,
|
|
174
|
+
neverBypassesWriteArbitration: true
|
|
175
|
+
},
|
|
176
|
+
isolation: {
|
|
177
|
+
prepCallbackMayUseNetworkAndSecrets: true,
|
|
178
|
+
editSandboxReceivesCallbackSecret: false,
|
|
179
|
+
singleUseContainerPreferred: runnerKind === "modal" || workspaceKind === "modal_sandbox",
|
|
180
|
+
callbackSecretRequiredForCallback: runnerKind === "modal" || providerKind === "workpool"
|
|
181
|
+
},
|
|
182
|
+
network: {
|
|
183
|
+
editValidationDefault: args.validationNeedsNetwork === true ? "allowed" : "blocked",
|
|
184
|
+
installPhaseAllowed: args.installPhaseAllowed === true,
|
|
185
|
+
validationCanRequestScopedInstall: true
|
|
186
|
+
},
|
|
187
|
+
callbacks: {
|
|
188
|
+
submitAuthRequired: true,
|
|
189
|
+
callbackHmacFormat: "convex_workpool_hmac_v1",
|
|
190
|
+
idempotentReceiptsRequired: true,
|
|
191
|
+
failClosedWithoutRunnerKey: true
|
|
192
|
+
},
|
|
193
|
+
localToCloud,
|
|
194
|
+
reasonCodes
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
function normalizeRequestedMode(value) {
|
|
198
|
+
if (value === "safe")
|
|
199
|
+
return "sandboxed";
|
|
200
|
+
return isAgentEditExecutionModeV1(value) ? value : undefined;
|
|
201
|
+
}
|
|
202
|
+
function defaultModeForContext(callerContext, workspaceKind) {
|
|
203
|
+
if (callerContext === "unknown" || workspaceKind === "unknown")
|
|
204
|
+
return "sandboxed";
|
|
205
|
+
if (isReviewLikeContext(callerContext) || isCloudLikeContext(callerContext, workspaceKind))
|
|
206
|
+
return "sandboxed";
|
|
207
|
+
return "scoped";
|
|
208
|
+
}
|
|
209
|
+
function defaultWorkspaceKind(callerContext) {
|
|
210
|
+
if (callerContext === "local_cli" || callerContext === "local_app" || callerContext === "pr_review_local" || callerContext === "review_local") {
|
|
211
|
+
return "local_worktree";
|
|
212
|
+
}
|
|
213
|
+
if (callerContext === "web_app" || callerContext === "cloud_worker" || callerContext === "pr_review_cloud" || callerContext === "review_cloud") {
|
|
214
|
+
return "modal_sandbox";
|
|
215
|
+
}
|
|
216
|
+
return "unknown";
|
|
217
|
+
}
|
|
218
|
+
function defaultRunnerKind(workspaceKind, callerContext) {
|
|
219
|
+
if (workspaceKind === "modal_sandbox" || workspaceKind === "cloud_ephemeral" || callerContext === "web_app" || callerContext === "cloud_worker")
|
|
220
|
+
return "modal";
|
|
221
|
+
if (workspaceKind === "local_worktree")
|
|
222
|
+
return "local_cli";
|
|
223
|
+
return "unknown";
|
|
224
|
+
}
|
|
225
|
+
function isLocalLikeContext(callerContext, workspaceKind) {
|
|
226
|
+
return workspaceKind === "local_worktree" || callerContext === "local_cli" || callerContext === "local_app";
|
|
227
|
+
}
|
|
228
|
+
function isCloudLikeContext(callerContext, workspaceKind) {
|
|
229
|
+
return workspaceKind === "modal_sandbox" || workspaceKind === "cloud_ephemeral" || workspaceKind === "provider_sandbox" || callerContext === "web_app" || callerContext === "cloud_worker" || callerContext === "pr_review_cloud" || callerContext === "review_cloud" || callerContext === "api";
|
|
230
|
+
}
|
|
231
|
+
function isReviewLikeContext(callerContext) {
|
|
232
|
+
return callerContext === "pr_review_local" || callerContext === "pr_review_cloud" || callerContext === "review_local" || callerContext === "review_cloud";
|
|
233
|
+
}
|
|
234
|
+
function resolveLocalToCloudPolicy(args) {
|
|
235
|
+
const localLike = isLocalLikeContext(args.callerContext, args.workspaceKind);
|
|
236
|
+
const requested = args.localToCloudRequested === true;
|
|
237
|
+
const reasonCodes = uniqueStrings([
|
|
238
|
+
requested ? "caller_requested_cloud" : undefined,
|
|
239
|
+
args.localSessionNeedsHandoff === true ? "local_session_needs_handoff" : undefined,
|
|
240
|
+
args.localOperatorLeaving === true ? "operator_left_local" : undefined,
|
|
241
|
+
args.yoloDenied ? "local_yolo_denied" : undefined,
|
|
242
|
+
args.validationNeedsNetwork === true ? "validation_needs_network" : undefined,
|
|
243
|
+
args.baselineMismatch === true || args.scopeRisk === "high" ? "baseline_or_scope_risk" : undefined,
|
|
244
|
+
isReviewLikeContext(args.callerContext) ? "review_surface_requires_sandbox" : undefined,
|
|
245
|
+
isCloudLikeContext(args.callerContext, args.workspaceKind) ? "web_or_cloud_default" : undefined
|
|
246
|
+
]);
|
|
247
|
+
const recommended = requested || localLike && (args.localSessionNeedsHandoff === true || args.localOperatorLeaving === true || args.yoloDenied || args.validationNeedsNetwork === true) || isReviewLikeContext(args.callerContext);
|
|
248
|
+
const allowed = recommended && args.cloudHandoffAllowed === true;
|
|
249
|
+
return {
|
|
250
|
+
requested,
|
|
251
|
+
recommended,
|
|
252
|
+
allowed,
|
|
253
|
+
reasonCodes,
|
|
254
|
+
sourceSessionId: args.sourceSessionId,
|
|
255
|
+
target: {
|
|
256
|
+
providerKind: "workpool",
|
|
257
|
+
runnerKind: "modal",
|
|
258
|
+
workspaceKind: "modal_sandbox",
|
|
259
|
+
editEngine: "opencode_run_json"
|
|
260
|
+
},
|
|
261
|
+
carry: {
|
|
262
|
+
allowedPaths: args.allowedPaths,
|
|
263
|
+
deniedPaths: args.deniedPaths,
|
|
264
|
+
validationCommand: args.validationCommand,
|
|
265
|
+
baselineRequired: true,
|
|
266
|
+
receiptBoundContext: true
|
|
267
|
+
},
|
|
268
|
+
nextAction: allowed ? "handoff_to_cloud" : recommended ? "offer_cloud_handoff" : "continue_local"
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
function uniqueStrings(values) {
|
|
272
|
+
const seen = new Set;
|
|
273
|
+
const output = [];
|
|
274
|
+
for (const value of values) {
|
|
275
|
+
const text = value?.trim();
|
|
276
|
+
if (!text || seen.has(text))
|
|
277
|
+
continue;
|
|
278
|
+
seen.add(text);
|
|
279
|
+
output.push(text);
|
|
280
|
+
}
|
|
281
|
+
return output;
|
|
282
|
+
}
|
|
283
|
+
export {
|
|
284
|
+
resolveAgentEditExecutionPolicyV1,
|
|
285
|
+
mapAgentEditOutcomeToExecutionReceiptStatus,
|
|
286
|
+
isAgentEditWorkspaceKindV1,
|
|
287
|
+
isAgentEditExecutionModeV1,
|
|
288
|
+
isAgentEditCallerContextV1,
|
|
289
|
+
buildAgentEditSessionHandoffV1,
|
|
290
|
+
AGENT_EDIT_SESSION_SCHEMA_VERSION,
|
|
291
|
+
AGENT_EDIT_SESSION_CONTRACT_VERSION,
|
|
292
|
+
AGENT_EDIT_EXECUTION_POLICY_VERSION
|
|
293
|
+
};
|