@stigmer/runner 3.2.0 → 3.2.2
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/dist/.build-fingerprint +1 -1
- package/dist/activities/call-transform.js +12 -2
- package/dist/activities/call-transform.js.map +1 -1
- package/dist/activities/call-validate.js +20 -2
- package/dist/activities/call-validate.js.map +1 -1
- package/dist/activities/discover-mcp-server.js +6 -20
- package/dist/activities/discover-mcp-server.js.map +1 -1
- package/dist/activities/execute-cursor/cost-guard.d.ts +41 -0
- package/dist/activities/execute-cursor/cost-guard.js +50 -0
- package/dist/activities/execute-cursor/cost-guard.js.map +1 -0
- package/dist/activities/execute-cursor/index.d.ts +12 -0
- package/dist/activities/execute-cursor/index.js +83 -12
- package/dist/activities/execute-cursor/index.js.map +1 -1
- package/dist/activities/execute-cursor/prompt-builder.d.ts +19 -0
- package/dist/activities/execute-cursor/prompt-builder.js +21 -0
- package/dist/activities/execute-cursor/prompt-builder.js.map +1 -1
- package/dist/activities/execute-cursor/turn-stream.d.ts +10 -1
- package/dist/activities/execute-cursor/turn-stream.js +42 -9
- package/dist/activities/execute-cursor/turn-stream.js.map +1 -1
- package/dist/activities/execute-deep-agent/prompt-builder.d.ts +19 -0
- package/dist/activities/execute-deep-agent/prompt-builder.js +12 -0
- package/dist/activities/execute-deep-agent/prompt-builder.js.map +1 -1
- package/dist/activities/execute-deep-agent/setup.js +4 -0
- package/dist/activities/execute-deep-agent/setup.js.map +1 -1
- package/dist/activities/workflow-event-activities.js +2 -0
- package/dist/activities/workflow-event-activities.js.map +1 -1
- package/dist/config.d.ts +17 -0
- package/dist/config.js +14 -0
- package/dist/config.js.map +1 -1
- package/dist/runner-manager.d.ts +2 -0
- package/dist/runner-manager.js +2 -1
- package/dist/runner-manager.js.map +1 -1
- package/dist/runner.d.ts +2 -0
- package/dist/runner.js +2 -1
- package/dist/runner.js.map +1 -1
- package/dist/shared/context-bridge.d.ts +30 -0
- package/dist/shared/context-bridge.js +45 -0
- package/dist/shared/context-bridge.js.map +1 -0
- package/dist/shared/sender-identity.d.ts +50 -0
- package/dist/shared/sender-identity.js +69 -0
- package/dist/shared/sender-identity.js.map +1 -0
- package/dist/shared/with-timeout.d.ts +17 -0
- package/dist/shared/with-timeout.js +34 -0
- package/dist/shared/with-timeout.js.map +1 -0
- package/dist/workflow-engine/do-executor.d.ts +7 -0
- package/dist/workflow-engine/do-executor.js +59 -1
- package/dist/workflow-engine/do-executor.js.map +1 -1
- package/dist/workflow-engine/tasks/call-function.js +68 -1
- package/dist/workflow-engine/tasks/call-function.js.map +1 -1
- package/dist/workflow-engine/types.d.ts +26 -0
- package/dist/workflow-engine/types.js.map +1 -1
- package/dist/workflows/engine-core.js +5 -1
- package/dist/workflows/engine-core.js.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/config.test.ts +8 -0
- package/src/activities/__tests__/call-validate.test.ts +137 -0
- package/src/activities/__tests__/classify-tool-approvals.test.ts +1 -0
- package/src/activities/__tests__/discover-mcp-server.test.ts +1 -0
- package/src/activities/__tests__/workflow-event-activities.test.ts +60 -0
- package/src/activities/call-transform.ts +20 -2
- package/src/activities/call-validate.ts +27 -2
- package/src/activities/discover-mcp-server.ts +7 -28
- package/src/activities/execute-cursor/__tests__/build-prompt.test.ts +65 -0
- package/src/activities/execute-cursor/__tests__/cost-guard.test.ts +64 -0
- package/src/activities/execute-cursor/__tests__/turn-stream.test.ts +118 -0
- package/src/activities/execute-cursor/cost-guard.ts +56 -0
- package/src/activities/execute-cursor/index.ts +101 -15
- package/src/activities/execute-cursor/prompt-builder.ts +44 -0
- package/src/activities/execute-cursor/turn-stream.ts +61 -10
- package/src/activities/execute-deep-agent/__tests__/hitl-reject.test.ts +1 -0
- package/src/activities/execute-deep-agent/__tests__/hitl-resume-approve-all.test.ts +1 -0
- package/src/activities/execute-deep-agent/__tests__/hitl-resume-history.test.ts +1 -0
- package/src/activities/execute-deep-agent/__tests__/index.test.ts +1 -0
- package/src/activities/execute-deep-agent/__tests__/prompt-builder.test.ts +58 -0
- package/src/activities/execute-deep-agent/__tests__/sequential-gate-resume.test.ts +1 -0
- package/src/activities/execute-deep-agent/prompt-builder.ts +35 -0
- package/src/activities/execute-deep-agent/setup.ts +4 -0
- package/src/activities/workflow-event-activities.ts +2 -0
- package/src/config.ts +23 -0
- package/src/runner-manager.ts +6 -1
- package/src/runner.ts +6 -1
- package/src/shared/__tests__/artifact-storage.test.ts +1 -0
- package/src/shared/__tests__/context-bridge.test.ts +51 -0
- package/src/shared/__tests__/sender-identity.test.ts +92 -0
- package/src/shared/__tests__/with-timeout.test.ts +45 -0
- package/src/shared/context-bridge.ts +51 -0
- package/src/shared/sender-identity.ts +85 -0
- package/src/shared/with-timeout.ts +39 -0
- package/src/workflow-engine/__tests__/do-executor.test.ts +155 -0
- package/src/workflow-engine/__tests__/tasks/call-function.test.ts +94 -0
- package/src/workflow-engine/do-executor.ts +65 -1
- package/src/workflow-engine/tasks/call-function.ts +84 -3
- package/src/workflow-engine/types.ts +27 -0
- package/src/workflows/__tests__/execute-serverless-workflow.test.ts +1 -0
- package/src/workflows/engine-core.ts +5 -1
package/dist/.build-fingerprint
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"hash":"
|
|
1
|
+
{"hash":"a3014a172896ae2b","builtAt":"2026-07-19T08:03:00.762Z","fileCount":255}
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* throw a non-retryable error until implemented.
|
|
14
14
|
*/
|
|
15
15
|
import { ApplicationFailure } from "@temporalio/activity";
|
|
16
|
-
import { evaluateExpression } from "../workflow-engine/expression.js";
|
|
16
|
+
import { evaluateExpression, isStrictExpr, sanitizeExpr, } from "../workflow-engine/expression.js";
|
|
17
17
|
function normalizeEngine(raw) {
|
|
18
18
|
return raw
|
|
19
19
|
.toUpperCase()
|
|
@@ -23,11 +23,21 @@ export async function transformAction(config, taskInput) {
|
|
|
23
23
|
if (!config.expression) {
|
|
24
24
|
throw ApplicationFailure.nonRetryable("transform: 'expression' is required", "TRANSFORM_MISSING_EXPRESSION");
|
|
25
25
|
}
|
|
26
|
+
if (typeof config.expression !== "string") {
|
|
27
|
+
throw ApplicationFailure.nonRetryable(`transform: 'expression' must be a jq string, got ${typeof config.expression}. ` +
|
|
28
|
+
"Fix the expression in the workflow's transform task_config.", "TRANSFORM_INVALID_EXPRESSION");
|
|
29
|
+
}
|
|
26
30
|
const engine = normalizeEngine(config.engine || "JQ");
|
|
27
31
|
if (engine !== "JQ") {
|
|
28
32
|
throw ApplicationFailure.nonRetryable(`transform: engine '${config.engine}' is not yet supported. Only JQ is currently implemented.`, "TRANSFORM_UNSUPPORTED_ENGINE");
|
|
29
33
|
}
|
|
30
34
|
const data = config.input !== undefined ? config.input : taskInput;
|
|
31
|
-
|
|
35
|
+
// The expression arrives unresolved (deferred code — see the
|
|
36
|
+
// call-function builder). Accept both the strict `${ ... }` wrapper
|
|
37
|
+
// and the bare jq form the converter emits.
|
|
38
|
+
const expression = isStrictExpr(config.expression)
|
|
39
|
+
? sanitizeExpr(config.expression)
|
|
40
|
+
: config.expression;
|
|
41
|
+
return evaluateExpression(expression, data, {});
|
|
32
42
|
}
|
|
33
43
|
//# sourceMappingURL=call-transform.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"call-transform.js","sourceRoot":"","sources":["../../src/activities/call-transform.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,
|
|
1
|
+
{"version":3,"file":"call-transform.js","sourceRoot":"","sources":["../../src/activities/call-transform.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,YAAY,GACb,MAAM,kCAAkC,CAAC;AAQ1C,SAAS,eAAe,CAAC,GAAW;IAClC,OA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poralio/activity";
|
|
20
|
-
import { evaluateExpression } from "../workflow-engine/expression.js";
|
|
20
|
+
import { evaluateExpression, isStrictExpr, sanitizeExpr, } from "../workflow-engine/expression.js";
|
|
21
21
|
function normalizeOnFail(raw) {
|
|
22
22
|
if (!raw)
|
|
23
23
|
return "RAISE";
|
|
@@ -118,7 +118,25 @@ function validateJsonSchema(data, schema) {
|
|
|
118
118
|
async function validateRules(data, rules) {
|
|
119
119
|
const errors = [];
|
|
120
120
|
for (const rule of rules) {
|
|
121
|
-
|
|
121
|
+
// Config guard: the expression must be a jq string. Anything else is
|
|
122
|
+
// a workflow-definition defect (or an upstream resolution bug) — name
|
|
123
|
+
// the rule and what to fix instead of crashing in the jq engine.
|
|
124
|
+
if (typeof rule.expression !== "string" || rule.expression.length === 0) {
|
|
125
|
+
errors.push({
|
|
126
|
+
rule: rule.name,
|
|
127
|
+
message: `Rule '${rule.name}' has an invalid 'expression': expected a jq ` +
|
|
128
|
+
`predicate string, got ${typeof rule.expression}. Fix the rule in ` +
|
|
129
|
+
`the workflow's validate task_config.`,
|
|
130
|
+
});
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
// Rule expressions arrive unresolved (deferred code — see the
|
|
134
|
+
// call-function builder). Accept both the strict `${ ... }` wrapper
|
|
135
|
+
// and a bare jq predicate.
|
|
136
|
+
const expr = isStrictExpr(rule.expression)
|
|
137
|
+
? sanitizeExpr(rule.expression)
|
|
138
|
+
: rule.expression;
|
|
139
|
+
const result = await evaluateExpression(expr, data, {});
|
|
122
140
|
if (!result) {
|
|
123
141
|
errors.push({
|
|
124
142
|
rule: rule.name,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"call-validate.js","sourceRoot":"","sources":["../../src/activities/call-validate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,
|
|
1
|
+
{"version":3,"file":"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O,EAAE,GAAG,MAAM,EAAE,kBAAkB,EAAE,MAAM,CAAC,aAAa,EAAE,CAAC;IACjE,CAAC;IAED,IAAI,CAAC,MAAM,CAAC,KAAK,IAAI,MAAM,KAAK,MAAM,EAAE,CAAC;QACvC,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QAClB,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC7D,MAAM,kBAAkB,CAAC,YAAY,CACnC,sBAAsB,OAAO,EAAE,EAC/B,mBAAmB,EACnB,MAAM,CACP,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -24,6 +24,7 @@ import { StigmerClient } from "../client/stigmer-client.js";
|
|
|
24
24
|
import { mcpServerToResolved } from "../shared/mcp-resolver.js";
|
|
25
25
|
import { toMcpClientConfig } from "../shared/mcp-manager.js";
|
|
26
26
|
import { detectOAuthChallenge } from "../shared/mcp-oauth-detect.js";
|
|
27
|
+
import { withTimeout } from "../shared/with-timeout.js";
|
|
27
28
|
const SESSION_INIT_TIMEOUT_MS = 270_000;
|
|
28
29
|
const PLATFORM_INJECTABLE_MAP = {
|
|
29
30
|
STIGMER_SERVER_ADDRESS: "STIGMER_MCP_PUBLIC_ENDPOINT",
|
|
@@ -185,7 +186,11 @@ async function connectAndDiscover(slug, connectionConfig) {
|
|
|
185
186
|
const tools = [];
|
|
186
187
|
const resourceTemplates = [];
|
|
187
188
|
try {
|
|
188
|
-
|
|
189
|
+
const timeoutMessage = `MCP server '${slug}' did not respond within ` +
|
|
190
|
+
`${Math.round(SESSION_INIT_TIMEOUT_MS / 1000)}s. If this server requires compilation or ` +
|
|
191
|
+
`package installation on first run (e.g. go run, npx), the cold ` +
|
|
192
|
+
`start may have exceeded the discovery timeout.`;
|
|
193
|
+
await withTimeout(SESSION_INIT_TIMEOUT_MS, timeoutMessage, async () => {
|
|
189
194
|
await client.initializeConnections();
|
|
190
195
|
const mcpClient = await client.getClient(slug);
|
|
191
196
|
if (!mcpClient) {
|
|
@@ -259,25 +264,6 @@ async function classifyHttpOAuthFailure(slug, connectionConfig) {
|
|
|
259
264
|
}
|
|
260
265
|
return detectOAuthChallenge(connection.url, connection.headers, slug);
|
|
261
266
|
}
|
|
262
|
-
async function withTimeout(ms, serverSlug, fn) {
|
|
263
|
-
return new Promise((resolve, reject) => {
|
|
264
|
-
const timer = setTimeout(() => {
|
|
265
|
-
reject(new Error(`MCP server '${serverSlug}' did not respond within ` +
|
|
266
|
-
`${Math.round(ms / 1000)}s. If this server requires compilation or ` +
|
|
267
|
-
`package installation on first run (e.g. go run, npx), the cold ` +
|
|
268
|
-
`start may have exceeded the discovery timeout.`));
|
|
269
|
-
}, ms);
|
|
270
|
-
fn()
|
|
271
|
-
.then((result) => {
|
|
272
|
-
clearTimeout(timer);
|
|
273
|
-
resolve(result);
|
|
274
|
-
})
|
|
275
|
-
.catch((err) => {
|
|
276
|
-
clearTimeout(timer);
|
|
277
|
-
reject(err);
|
|
278
|
-
});
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
267
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
282
268
|
// Temporal Activity Factory
|
|
283
269
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discover-mcp-server.js","sourceRoot":"","sources":["../../src/activities/discover-mcp-server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAAE,aAAa,EAA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CAAC,CAAC;IAEH,OAAO;QACL,6BAA6B,EAAE,KAAK,EAClC,KAA6B,EACK,EAAE;YACpC,eAAe,EAAE,CAAC;YAClB,IAAI,CAAC;gBACH,OAAO,MAAM,iBAAiB,CAAC,KAAK,EAAE,EAAE,aAAa,EAAE,CAAC,CAAC;YAC3D,CAAC;oBAAS,CAAC;gBACT,gBAAgB,EAAE,CAAC;YACrB,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ExecutionConfig.max_cost_usd enforcement for the Cursor harness.
|
|
3
|
+
*
|
|
4
|
+
* The native harness enforces the cap in middleware (cost-cap.ts): tools are
|
|
5
|
+
* blocked at the threshold and the model gets one final tool-free round to
|
|
6
|
+
* summarize. Cursor's only control point is cancelling the in-flight run, so
|
|
7
|
+
* here the cap is a HARD stop — the shared onDelta flags the overrun when a
|
|
8
|
+
* turn-ended usage delta lands, and the stream loop ends the run through the
|
|
9
|
+
* same clean-cancel pattern the stall watchdog and first-denial stop use.
|
|
10
|
+
* Slightly harsher than native by construction; both harnesses terminate with
|
|
11
|
+
* the same honesty semantics (EXECUTION_TERMINATED, work checkpointed, the
|
|
12
|
+
* conversation continues on the next message — the recursion-limit precedent
|
|
13
|
+
* in execute-deep-agent/streaming-terminal.ts).
|
|
14
|
+
*
|
|
15
|
+
* The running figure is the usage accumulator's local pricing-table estimate
|
|
16
|
+
* (authoritative billing is the BiDi proxy). That is the same estimation
|
|
17
|
+
* basis the native cost-cap middleware uses — acceptable for a safety net.
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Whether the per-execution cost budget has been exhausted.
|
|
21
|
+
*
|
|
22
|
+
* `maxCostUsd <= 0` means "no cap" (the proto contract: 0/unset disables the
|
|
23
|
+
* ceiling). The boundary is inclusive: reaching the cap exactly stops the run,
|
|
24
|
+
* matching the native middleware's `runningCost >= maxCostUsd` check.
|
|
25
|
+
*/
|
|
26
|
+
export declare function costCapExceeded(maxCostUsd: number, estimatedCostUsd: number): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Stable prefix of the cost-limit terminal error. Mirrors the cross-repo
|
|
29
|
+
* pattern of TOOL_CALL_LIMIT_ERROR_PREFIX (streaming-terminal.ts): consumers
|
|
30
|
+
* that need to distinguish "ran out of cost budget" from other TERMINATED
|
|
31
|
+
* causes can match on this prefix, because AgentExecutionStatus carries no
|
|
32
|
+
* structured termination reason. Do not reword without checking consumers.
|
|
33
|
+
*/
|
|
34
|
+
export declare const COST_LIMIT_ERROR_PREFIX = "Agent reached the cost limit";
|
|
35
|
+
/** The terminal `status.error` for a cost-cap stop. */
|
|
36
|
+
export declare function formatCostLimitError(maxCostUsd: number, estimatedCostUsd: number): string;
|
|
37
|
+
/**
|
|
38
|
+
* User-facing system message for a cost-cap stop. Parallel to the
|
|
39
|
+
* recursion-limit copy: honest about the limit, clear that nothing is lost.
|
|
40
|
+
*/
|
|
41
|
+
export declare const COST_LIMIT_USER_COPY: string;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ExecutionConfig.max_cost_usd enforcement for the Cursor harness.
|
|
3
|
+
*
|
|
4
|
+
* The native harness enforces the cap in middleware (cost-cap.ts): tools are
|
|
5
|
+
* blocked at the threshold and the model gets one final tool-free round to
|
|
6
|
+
* summarize. Cursor's only control point is cancelling the in-flight run, so
|
|
7
|
+
* here the cap is a HARD stop — the shared onDelta flags the overrun when a
|
|
8
|
+
* turn-ended usage delta lands, and the stream loop ends the run through the
|
|
9
|
+
* same clean-cancel pattern the stall watchdog and first-denial stop use.
|
|
10
|
+
* Slightly harsher than native by construction; both harnesses terminate with
|
|
11
|
+
* the same honesty semantics (EXECUTION_TERMINATED, work checkpointed, the
|
|
12
|
+
* conversation continues on the next message — the recursion-limit precedent
|
|
13
|
+
* in execute-deep-agent/streaming-terminal.ts).
|
|
14
|
+
*
|
|
15
|
+
* The running figure is the usage accumulator's local pricing-table estimate
|
|
16
|
+
* (authoritative billing is the BiDi proxy). That is the same estimation
|
|
17
|
+
* basis the native cost-cap middleware uses — acceptable for a safety net.
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Whether the per-execution cost budget has been exhausted.
|
|
21
|
+
*
|
|
22
|
+
* `maxCostUsd <= 0` means "no cap" (the proto contract: 0/unset disables the
|
|
23
|
+
* ceiling). The boundary is inclusive: reaching the cap exactly stops the run,
|
|
24
|
+
* matching the native middleware's `runningCost >= maxCostUsd` check.
|
|
25
|
+
*/
|
|
26
|
+
export function costCapExceeded(maxCostUsd, estimatedCostUsd) {
|
|
27
|
+
return maxCostUsd > 0 && estimatedCostUsd >= maxCostUsd;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Stable prefix of the cost-limit terminal error. Mirrors the cross-repo
|
|
31
|
+
* pattern of TOOL_CALL_LIMIT_ERROR_PREFIX (streaming-terminal.ts): consumers
|
|
32
|
+
* that need to distinguish "ran out of cost budget" from other TERMINATED
|
|
33
|
+
* causes can match on this prefix, because AgentExecutionStatus carries no
|
|
34
|
+
* structured termination reason. Do not reword without checking consumers.
|
|
35
|
+
*/
|
|
36
|
+
export const COST_LIMIT_ERROR_PREFIX = "Agent reached the cost limit";
|
|
37
|
+
/** The terminal `status.error` for a cost-cap stop. */
|
|
38
|
+
export function formatCostLimitError(maxCostUsd, estimatedCostUsd) {
|
|
39
|
+
return (`${COST_LIMIT_ERROR_PREFIX} for this message ` +
|
|
40
|
+
`(~$${estimatedCostUsd.toFixed(4)} of the $${maxCostUsd.toFixed(2)} budget). ` +
|
|
41
|
+
`Send another message to continue.`);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* User-facing system message for a cost-cap stop. Parallel to the
|
|
45
|
+
* recursion-limit copy: honest about the limit, clear that nothing is lost.
|
|
46
|
+
*/
|
|
47
|
+
export const COST_LIMIT_USER_COPY = "The agent reached the cost limit for this message. " +
|
|
48
|
+
"Work completed so far has been saved. " +
|
|
49
|
+
"Send another message to continue where the agent left off.";
|
|
50
|
+
//# sourceMappingURL=cost-guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cost-guard.js","sourceRoot":"","sources":["../../../src/activities/execute-cursor/cost-guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAAC,UAAkB,EAAE,gBAAwB;IAC1E,OAAO,UAAU,GAAG,CAAC,IAAI,gBAAgB,IAAI,UAAU,CAAC;AAC1D,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,8BAA8B,CAAC;AAEtE,uDAAuD;AACvD,MAAM,UAAU,oBAAoB,CAAC,UAAkB,EAAE,gBAAwB;IAC/E,OAAO,CACL,GAAG,uBAAuB,oBAAoB;QAC9C,MAAM,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC,YAAY,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,YAAY;QAC9E,mCAAmC,CACpC,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAC/B,qDAAqD;IACrD,wCAAwC;IACxC,4DAA4D,CAAC"}
|
|
@@ -59,6 +59,18 @@ export interface BuildPromptInput {
|
|
|
59
59
|
* .build_from_plan): both prompt paths carry the implement-plan directive.
|
|
60
60
|
*/
|
|
61
61
|
buildFromPlan?: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Rollover context bridge from `SessionSpec.metadata` (cloud DD-013).
|
|
64
|
+
* Only the enhanced-prompt path consumes it — a resumed agent's native
|
|
65
|
+
* context IS the previous conversation, so it needs no bridge.
|
|
66
|
+
*/
|
|
67
|
+
contextBridge?: string;
|
|
68
|
+
/**
|
|
69
|
+
* Channel sender identity from `SessionSpec.metadata`. Like the bridge,
|
|
70
|
+
* only the enhanced-prompt path consumes it — a resumed agent's native
|
|
71
|
+
* context already carries it from the session's first turn.
|
|
72
|
+
*/
|
|
73
|
+
senderIdentity?: import("../../shared/sender-identity.js").SenderIdentity;
|
|
62
74
|
}
|
|
63
75
|
/**
|
|
64
76
|
* Select and build the appropriate prompt based on resolution reason and
|
|
@@ -37,6 +37,8 @@ import { CursorMode } from "@stigmer/protos/ai/stigmer/agentic/session/v1/enum_p
|
|
|
37
37
|
import { determineCursorMode, isCloudMode } from "./cursor-mode.js";
|
|
38
38
|
import { MessageAccumulator, cancelInProgressSubAgentProtos, collapseRedundantToolCallTwins } from "./message-translator.js";
|
|
39
39
|
import { utcTimestamp, persistStatus, reportSetupProgress, slimStatus } from "../../shared/status.js";
|
|
40
|
+
import { readContextBridge } from "../../shared/context-bridge.js";
|
|
41
|
+
import { readSenderIdentity } from "../../shared/sender-identity.js";
|
|
40
42
|
import { withholdSecretContentFromMessages } from "../../shared/tool-row.js";
|
|
41
43
|
import { StallTimeoutError, formatStallFailure } from "../../shared/stall-watchdog.js";
|
|
42
44
|
import { resolveUsableArtifactStorage, loadArtifactStorageConfig } from "../../shared/artifact-storage.js";
|
|
@@ -66,6 +68,7 @@ import { isGitWorkTree } from "../../shared/filereview/git-substrate.js";
|
|
|
66
68
|
import { captureBaselineToLedger, buildCursorProgressSubstrate, applyCaptureDecisions, deriveCaptureMode, } from "./capture-flow.js";
|
|
67
69
|
import { runTurnBoundary } from "./turn-boundary.js";
|
|
68
70
|
import { consumeCursorTurnStream, makeCursorTurnOnDelta, newTurnStreamState, } from "./turn-stream.js";
|
|
71
|
+
import { formatCostLimitError, COST_LIMIT_USER_COPY } from "./cost-guard.js";
|
|
69
72
|
import { newProgressCaptureState, } from "../../shared/filereview/progress.js";
|
|
70
73
|
import { deriveExecutionFingerprintKey } from "../../shared/approval-fingerprint.js";
|
|
71
74
|
import { getRunnerHitlMasterSecret } from "../../shared/fingerprint-secret.js";
|
|
@@ -84,6 +87,7 @@ import { synthesizeError, formatClassifiedError, shouldRetryWithFreshAgent } fro
|
|
|
84
87
|
import { createAgent, createCloudAgent } from "./session-lifecycle.js";
|
|
85
88
|
import { setMaxListeners } from "node:events";
|
|
86
89
|
import { startHeartbeat } from "../../shared/heartbeat.js";
|
|
90
|
+
import { withTimeout } from "../../shared/with-timeout.js";
|
|
87
91
|
import { getShutdownSignalForQueue } from "../../runner-manager.js";
|
|
88
92
|
/**
|
|
89
93
|
* Creates the activity functions bound to the runner config.
|
|
@@ -202,6 +206,24 @@ turnSeq) {
|
|
|
202
206
|
// Carries model/mode/agentId out to the outer catch so a thrown CursorSdkError
|
|
203
207
|
// can be classified with the same context as the run.wait() error path.
|
|
204
208
|
let errorContext = { model: "default", mode: "local", agentId: "" };
|
|
209
|
+
// Periodic heartbeat for the ENTIRE activity, started before any phase runs.
|
|
210
|
+
// Setup phases make network calls (blueprint resolution, workspace clone, MCP
|
|
211
|
+
// backfill, Agent.create) that can stall; the scattered manual heartbeat()
|
|
212
|
+
// pulses between them leave every individual call uncovered. The production
|
|
213
|
+
// stale-proxy incident hung inside Agent.create with zero heartbeats and
|
|
214
|
+
// surfaced as an opaque 5-minute Temporal timeout. The label names the
|
|
215
|
+
// current phase so a stall is attributed in Temporal heartbeat details, and
|
|
216
|
+
// cancellation stays observable throughout. Safe ONLY because every SDK call
|
|
217
|
+
// below is itself bounded (agentResolveTimeoutMs, stall watchdog) — an
|
|
218
|
+
// unbounded hang under a live heartbeat would keep a dead activity alive
|
|
219
|
+
// forever.
|
|
220
|
+
let heartbeatPhase = "setup";
|
|
221
|
+
const taskQueue = Context.current().info.taskQueue;
|
|
222
|
+
const shutdownSignal = getShutdownSignalForQueue(taskQueue);
|
|
223
|
+
periodicHeartbeat = startHeartbeat(30_000, () => ({
|
|
224
|
+
phase: heartbeatPhase,
|
|
225
|
+
execution: executionId,
|
|
226
|
+
}), { shutdownSignal });
|
|
205
227
|
try {
|
|
206
228
|
// Phase 1: Hydrate execution from DB
|
|
207
229
|
await reportSetupProgress(client, executionId, "Fetching execution");
|
|
@@ -213,6 +235,7 @@ turnSeq) {
|
|
|
213
235
|
session = await client.getSession(sessionId);
|
|
214
236
|
const blueprint = await resolveBlueprint(client, session, config.workspaceRootDir);
|
|
215
237
|
// Phase 2b: Resolve execution environment (MCP server credentials)
|
|
238
|
+
heartbeatPhase = "resolving_environment";
|
|
216
239
|
await reportSetupProgress(client, executionId, "Resolving environment");
|
|
217
240
|
const { envVars, secretKeys } = await resolveExecutionEnv(client, executionId);
|
|
218
241
|
heartbeat();
|
|
@@ -222,6 +245,7 @@ turnSeq) {
|
|
|
222
245
|
// disabled the runner must provision the workspace itself, mirroring the
|
|
223
246
|
// native harness. Git provisioning is idempotent across multi-turn and
|
|
224
247
|
// HITL reinvocations.
|
|
248
|
+
heartbeatPhase = "provisioning_workspace";
|
|
225
249
|
await reportSetupProgress(client, executionId, "Provisioning workspace");
|
|
226
250
|
const workspaceProvision = await provisionCursorWorkspace(config, session, envVars, sessionId ?? "");
|
|
227
251
|
blueprint.workspaceDirs = workspaceProvision.workspaceDirs;
|
|
@@ -472,6 +496,7 @@ turnSeq) {
|
|
|
472
496
|
await reportSetupProgress(client, executionId, "Resolving MCP servers");
|
|
473
497
|
let mcpResolution = await resolveMcpServers(client, blueprint.mergedMcpServerUsages, envVars);
|
|
474
498
|
// Phase 4a: Connect backfill for undiscovered MCP servers
|
|
499
|
+
heartbeatPhase = "resolving_mcp_servers";
|
|
475
500
|
const sessionOrg = session.metadata?.org ?? "";
|
|
476
501
|
mcpResolution = await backfillMcpServersIfNeeded(client, mcpResolution, blueprint.mergedMcpServerUsages, envVars, sessionOrg, heartbeat, secretKeys);
|
|
477
502
|
const mcpConfig = mcpResolution.cursorConfig;
|
|
@@ -683,7 +708,18 @@ turnSeq) {
|
|
|
683
708
|
mcpServers: mcpConfig,
|
|
684
709
|
agents: cursorSubAgents,
|
|
685
710
|
};
|
|
686
|
-
|
|
711
|
+
// Agent.create/Agent.resume have no timeout of their own — a degraded
|
|
712
|
+
// transport (dead proxy connection, stale HTTP/2 session) hangs them
|
|
713
|
+
// forever, which the periodic heartbeat would happily keep alive. The
|
|
714
|
+
// bound converts that hang into an immediate, named transport failure.
|
|
715
|
+
// The message carries "timed out" so the error classifier's network
|
|
716
|
+
// patterns mark it retryable.
|
|
717
|
+
heartbeatPhase = "resolving_agent";
|
|
718
|
+
const resolveTimeoutSeconds = Math.round(config.agentResolveTimeoutMs / 1000);
|
|
719
|
+
let resolution = await withTimeout(config.agentResolveTimeoutMs, () => `Cursor agent ${threadId ? "resume" : "create"} timed out after ${resolveTimeoutSeconds}s ` +
|
|
720
|
+
`(${config.proxyEndpoint ? `via proxy ${config.proxyEndpoint}` : "direct Cursor API connection"}). ` +
|
|
721
|
+
`The transport connection is likely dead. Retry the message; if this persists, ` +
|
|
722
|
+
`check proxy and network health.`, () => resolveAgent(threadId, createOptions, agentMode));
|
|
687
723
|
console.log(`ExecuteCursor agent resolved: execution=${executionId}, ` +
|
|
688
724
|
`reason=${resolution.reason}, mode=${resolution.mode}, ` +
|
|
689
725
|
`agentId=${resolution.agentId}, resumed=${resolution.resumed}` +
|
|
@@ -731,6 +767,8 @@ turnSeq) {
|
|
|
731
767
|
appliedToolCallIds,
|
|
732
768
|
interactionMode,
|
|
733
769
|
buildFromPlan,
|
|
770
|
+
contextBridge: readContextBridge(blueprint.sessionSpec.metadata),
|
|
771
|
+
senderIdentity: readSenderIdentity(blueprint.sessionSpec.metadata),
|
|
734
772
|
});
|
|
735
773
|
// Phase 10a: Inject structured output instruction for Cursor harness
|
|
736
774
|
let effectivePrompt = prompt;
|
|
@@ -795,6 +833,7 @@ turnSeq) {
|
|
|
795
833
|
// The shared onDelta only needs the usage/enricher/heartbeat/state subset,
|
|
796
834
|
// and it is wired at SEND time — before the accumulator exists — so it takes
|
|
797
835
|
// the narrow deps. The primary send and both retry sends reuse this object.
|
|
836
|
+
const maxCostUsd = spec.executionConfig?.maxCostUsd ?? 0;
|
|
798
837
|
const onDeltaDeps = {
|
|
799
838
|
usageAccumulator,
|
|
800
839
|
deltaEnricher,
|
|
@@ -802,17 +841,12 @@ turnSeq) {
|
|
|
802
841
|
promptEstimatedTokens,
|
|
803
842
|
executionId,
|
|
804
843
|
state: turnState,
|
|
844
|
+
maxCostUsd,
|
|
805
845
|
};
|
|
806
|
-
//
|
|
807
|
-
// (
|
|
808
|
-
//
|
|
809
|
-
|
|
810
|
-
const taskQueue = Context.current().info.taskQueue;
|
|
811
|
-
const shutdownSignal = getShutdownSignalForQueue(taskQueue);
|
|
812
|
-
periodicHeartbeat = startHeartbeat(30_000, () => ({
|
|
813
|
-
phase: "cursor_streaming",
|
|
814
|
-
execution: executionId,
|
|
815
|
-
}), { shutdownSignal });
|
|
846
|
+
// The activity-wide periodic heartbeat (started at entry) keeps Temporal
|
|
847
|
+
// informed during silent SDK operations (long tool calls, MCP requests,
|
|
848
|
+
// model thinking); relabel it for the streaming phase.
|
|
849
|
+
heartbeatPhase = "cursor_streaming";
|
|
816
850
|
// The Cursor SDK registers abort listeners on the cancellation signal for
|
|
817
851
|
// each concurrent tool call (fetch, MCP, shell). With 10+ parallel tools,
|
|
818
852
|
// Node's default limit of 10 triggers MaxListenersExceededWarning. This is
|
|
@@ -904,6 +938,7 @@ turnSeq) {
|
|
|
904
938
|
if (turnState.pauseDetected ||
|
|
905
939
|
workerShutdownDetected ||
|
|
906
940
|
turnState.stallDetected ||
|
|
941
|
+
turnState.costCapExceeded ||
|
|
907
942
|
Context.current().cancellationSignal.aborted) {
|
|
908
943
|
accumulator.cancelInProgressSubAgents();
|
|
909
944
|
}
|
|
@@ -936,6 +971,32 @@ turnSeq) {
|
|
|
936
971
|
console.warn(`ExecuteCursor stalled: execution=${executionId}, events=${turnState.eventCount}, error=${status.error}`);
|
|
937
972
|
return { kind: "return" };
|
|
938
973
|
}
|
|
974
|
+
// Cost cap (cost-guard.ts): onDelta flagged the overrun and the loop
|
|
975
|
+
// cancelled the run. EXECUTION_TERMINATED, not FAILED — the platform
|
|
976
|
+
// deliberately stopped the run, work is checkpointed, and the
|
|
977
|
+
// conversation continues on the next message (the recursion-limit
|
|
978
|
+
// precedent in execute-deep-agent/streaming-terminal.ts). RETURN (not
|
|
979
|
+
// throw): a Temporal retry would re-run the identical prompt and burn
|
|
980
|
+
// the same budget again.
|
|
981
|
+
if (turnState.costCapExceeded) {
|
|
982
|
+
const estimated = usageAccumulator.snapshot().estimatedCostUsd;
|
|
983
|
+
status.phase = ExecutionPhase.EXECUTION_TERMINATED;
|
|
984
|
+
status.error = formatCostLimitError(maxCostUsd, estimated);
|
|
985
|
+
status.completedAt = utcTimestamp();
|
|
986
|
+
status.messages.push(create(AgentMessageSchema, {
|
|
987
|
+
type: MessageType.MESSAGE_SYSTEM,
|
|
988
|
+
content: COST_LIMIT_USER_COPY,
|
|
989
|
+
timestamp: utcTimestamp(),
|
|
990
|
+
}));
|
|
991
|
+
await persist(status);
|
|
992
|
+
try {
|
|
993
|
+
resolution.agent.close();
|
|
994
|
+
}
|
|
995
|
+
catch { /* best effort */ }
|
|
996
|
+
console.warn(`ExecuteCursor terminated (cost cap): execution=${executionId}, ` +
|
|
997
|
+
`estimatedCostUsd=${estimated.toFixed(4)}, maxCostUsd=${maxCostUsd.toFixed(2)}`);
|
|
998
|
+
return { kind: "return" };
|
|
999
|
+
}
|
|
939
1000
|
// Worker shutdown: the runner-manager aborted the shutdown signal. NOT a
|
|
940
1001
|
// user pause. Checked via the shutdown signal directly so a retry (whose
|
|
941
1002
|
// periodic heartbeat is already stopped) still classifies it correctly.
|
|
@@ -1199,6 +1260,8 @@ turnSeq) {
|
|
|
1199
1260
|
attachmentPaths,
|
|
1200
1261
|
pendingApprovals: adjudicatedApprovals,
|
|
1201
1262
|
interactionMode,
|
|
1263
|
+
contextBridge: readContextBridge(blueprint.sessionSpec.metadata),
|
|
1264
|
+
senderIdentity: readSenderIdentity(blueprint.sessionSpec.metadata),
|
|
1202
1265
|
});
|
|
1203
1266
|
console.log(`ExecuteCursor retry with fresh agent: execution=${executionId}, ` +
|
|
1204
1267
|
`newAgentId=${freshAgent.agentId}`);
|
|
@@ -1547,6 +1610,11 @@ turnSeq) {
|
|
|
1547
1610
|
return slimStatus(status);
|
|
1548
1611
|
}
|
|
1549
1612
|
finally {
|
|
1613
|
+
// Stop the activity-wide periodic heartbeat on EVERY exit path
|
|
1614
|
+
// (idempotent). The epilogue and catch stop it at the pause/shutdown
|
|
1615
|
+
// disambiguation points; this covers early returns (e.g. the
|
|
1616
|
+
// pure-reconcile resume) so no orphaned timer survives the activity.
|
|
1617
|
+
periodicHeartbeat?.stop();
|
|
1550
1618
|
// End the OTel turn span + record metrics with the final token snapshot on
|
|
1551
1619
|
// EVERY exit path (idempotent). Placed here so the span covers any recovery
|
|
1552
1620
|
// retry (whose tokens accrue after the primary stream) and never leaks on an
|
|
@@ -1693,7 +1761,8 @@ export function buildPrompt(input) {
|
|
|
1693
1761
|
: userMessage;
|
|
1694
1762
|
}
|
|
1695
1763
|
// First execution, or a fresh agent created after a resume failure: there is
|
|
1696
|
-
// no prior conversation to inherit, so start a new turn with full context
|
|
1764
|
+
// no prior conversation to inherit, so start a new turn with full context —
|
|
1765
|
+
// including the rollover bridge, when the session carries one.
|
|
1697
1766
|
return buildEnhancedPrompt({
|
|
1698
1767
|
instructions,
|
|
1699
1768
|
userMessage,
|
|
@@ -1704,6 +1773,8 @@ export function buildPrompt(input) {
|
|
|
1704
1773
|
attachmentPaths,
|
|
1705
1774
|
interactionMode,
|
|
1706
1775
|
buildFromPlan,
|
|
1776
|
+
contextBridge: input.contextBridge,
|
|
1777
|
+
senderIdentity: input.senderIdentity,
|
|
1707
1778
|
});
|
|
1708
1779
|
}
|
|
1709
1780
|
// ---------------------------------------------------------------------------
|