@stigmer/runner 3.1.2 → 3.1.3
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/execute-cursor/attachment-resolver.d.ts +1 -1
- package/dist/activities/execute-cursor/attachment-resolver.js +1 -1
- package/dist/activities/execute-cursor/capture-flow.d.ts +18 -0
- package/dist/activities/execute-cursor/capture-flow.js +21 -0
- package/dist/activities/execute-cursor/capture-flow.js.map +1 -1
- package/dist/activities/execute-cursor/index.js +121 -139
- package/dist/activities/execute-cursor/index.js.map +1 -1
- package/dist/activities/execute-cursor/turn-boundary.d.ts +108 -0
- package/dist/activities/execute-cursor/turn-boundary.js +163 -0
- package/dist/activities/execute-cursor/turn-boundary.js.map +1 -0
- package/dist/activities/execute-deep-agent/index.js +30 -3
- package/dist/activities/execute-deep-agent/index.js.map +1 -1
- package/dist/activities/execute-deep-agent/streaming-v3.js +6 -1
- package/dist/activities/execute-deep-agent/streaming-v3.js.map +1 -1
- package/dist/activities/execute-deep-agent/streaming.d.ts +7 -0
- package/dist/activities/execute-deep-agent/streaming.js +5 -1
- package/dist/activities/execute-deep-agent/streaming.js.map +1 -1
- package/dist/shared/filereview/capture.d.ts +18 -1
- package/dist/shared/filereview/capture.js +105 -28
- package/dist/shared/filereview/capture.js.map +1 -1
- package/dist/shared/filereview/cas-substrate.d.ts +9 -0
- package/dist/shared/filereview/cas-substrate.js +9 -1
- package/dist/shared/filereview/cas-substrate.js.map +1 -1
- package/dist/shared/filereview/events.d.ts +16 -0
- package/dist/shared/filereview/events.js +37 -0
- package/dist/shared/filereview/events.js.map +1 -1
- package/dist/shared/filereview/git-substrate.d.ts +42 -0
- package/dist/shared/filereview/git-substrate.js +78 -0
- package/dist/shared/filereview/git-substrate.js.map +1 -1
- package/dist/shared/filereview/index.d.ts +3 -1
- package/dist/shared/filereview/index.js +3 -1
- package/dist/shared/filereview/index.js.map +1 -1
- package/dist/shared/filereview/line-counts.d.ts +48 -0
- package/dist/shared/filereview/line-counts.js +72 -0
- package/dist/shared/filereview/line-counts.js.map +1 -0
- package/dist/shared/filereview/progress.d.ts +96 -0
- package/dist/shared/filereview/progress.js +134 -0
- package/dist/shared/filereview/progress.js.map +1 -0
- package/dist/shared/implement-plan-prompt.d.ts +6 -4
- package/dist/shared/implement-plan-prompt.js +38 -6
- package/dist/shared/implement-plan-prompt.js.map +1 -1
- package/dist/shared/plan-artifact.d.ts +59 -11
- package/dist/shared/plan-artifact.js +144 -16
- package/dist/shared/plan-artifact.js.map +1 -1
- package/dist/shared/plan-mode-prompt.d.ts +6 -4
- package/dist/shared/plan-mode-prompt.js +10 -5
- package/dist/shared/plan-mode-prompt.js.map +1 -1
- package/package.json +3 -2
- package/src/activities/execute-cursor/__tests__/build-prompt.test.ts +7 -0
- package/src/activities/execute-cursor/__tests__/delta-enricher.test.ts +68 -0
- package/src/activities/execute-cursor/__tests__/turn-boundary.test.ts +280 -0
- package/src/activities/execute-cursor/attachment-resolver.ts +1 -1
- package/src/activities/execute-cursor/capture-flow.ts +32 -0
- package/src/activities/execute-cursor/index.ts +130 -153
- package/src/activities/execute-cursor/turn-boundary.ts +274 -0
- package/src/activities/execute-deep-agent/__tests__/prompt-builder.test.ts +11 -0
- package/src/activities/execute-deep-agent/index.ts +34 -3
- package/src/activities/execute-deep-agent/streaming-v3.ts +6 -1
- package/src/activities/execute-deep-agent/streaming.ts +12 -1
- package/src/shared/__tests__/implement-plan-prompt.test.ts +40 -2
- package/src/shared/__tests__/plan-artifact.test.ts +142 -9
- package/src/shared/filereview/__tests__/capture.test.ts +182 -1
- package/src/shared/filereview/__tests__/cas-substrate.test.ts +34 -0
- package/src/shared/filereview/__tests__/events.test.ts +105 -0
- package/src/shared/filereview/__tests__/line-counts.test.ts +73 -0
- package/src/shared/filereview/__tests__/progress.test.ts +236 -0
- package/src/shared/filereview/capture.ts +134 -30
- package/src/shared/filereview/cas-substrate.ts +17 -1
- package/src/shared/filereview/events.ts +50 -0
- package/src/shared/filereview/git-substrate.ts +108 -0
- package/src/shared/filereview/index.ts +22 -1
- package/src/shared/filereview/line-counts.ts +83 -0
- package/src/shared/filereview/progress.ts +186 -0
- package/src/shared/implement-plan-prompt.ts +39 -8
- package/src/shared/plan-artifact.ts +152 -16
- package/src/shared/plan-mode-prompt.ts +10 -5
|
@@ -2,11 +2,30 @@
|
|
|
2
2
|
* Plan-mode artifact publishing.
|
|
3
3
|
*
|
|
4
4
|
* When an execution runs in Plan mode (InteractionMode.PLAN), the agent's final
|
|
5
|
-
* message IS the plan. We publish that text as a first-class
|
|
5
|
+
* message IS the plan. We publish that text as a first-class plan markdown
|
|
6
6
|
* ExecutionArtifact so the UI can render a reviewable Plan card with
|
|
7
7
|
* copy/download, and a follow-up "Implement" execution can reference it
|
|
8
8
|
* deterministically.
|
|
9
9
|
*
|
|
10
|
+
* The artifact is named from the plan's own title — a hyphenated slug of its
|
|
11
|
+
* leading `# H1`, a `_<hash>` discriminator, and a `.plan.md` suffix (e.g.
|
|
12
|
+
* `plan-card-ux-cleanup_a1b2c3d4.plan.md`), so a downloaded plan lands as a
|
|
13
|
+
* recognizable file and the card, plan tab, and saved file all agree on one
|
|
14
|
+
* name. A plan with no derivable title falls back to a bare `<hash>.plan.md`.
|
|
15
|
+
*
|
|
16
|
+
* The `_<hash>` discriminator (first 8 hex of the plan content's SHA-256) is
|
|
17
|
+
* NOT for storage uniqueness — storage keys are already execution-scoped
|
|
18
|
+
* (`artifacts/{execId}/<name>`). It exists because the artifact BASENAME is a
|
|
19
|
+
* user-facing shared namespace: downloads save under it (see the artifact
|
|
20
|
+
* download disposition) and the artifact list surfaces it, so two same-titled
|
|
21
|
+
* plans would otherwise collide in the user's Downloads folder and read
|
|
22
|
+
* identically in the list. Deriving it from content (not a random or
|
|
23
|
+
* execution-scoped value) keeps naming honestly idempotent — identical content
|
|
24
|
+
* yields an identical name, so a finalize retry re-uploads to the same key,
|
|
25
|
+
* while any real edit yields a distinct one. This refines DD-23 §D3 ("no
|
|
26
|
+
* uniqueness hash"), which was correct about storage but overlooked the
|
|
27
|
+
* download/list basename namespace introduced by DD-23 §D1.
|
|
28
|
+
*
|
|
10
29
|
* This is deliberately a single, harness-agnostic helper:
|
|
11
30
|
* - The native (deepagents) harness already auto-publishes files an agent
|
|
12
31
|
* writes (InlinePublisher), but Plan mode is read-only, so there is no file to
|
|
@@ -21,8 +40,8 @@
|
|
|
21
40
|
*
|
|
22
41
|
* The plan content is NOT duplicated as a separate stored blob beyond this
|
|
23
42
|
* artifact — the chat message remains the live/streamed view; the artifact is
|
|
24
|
-
* the durable/exportable view, detected by convention (a FILE artifact
|
|
25
|
-
*
|
|
43
|
+
* the durable/exportable view, detected by convention (a FILE artifact whose
|
|
44
|
+
* name satisfies {@link isPlanArtifactName}).
|
|
26
45
|
*/
|
|
27
46
|
|
|
28
47
|
import { createHash } from "node:crypto";
|
|
@@ -36,15 +55,129 @@ import {
|
|
|
36
55
|
import type { ArtifactStorage } from "./artifact-storage.js";
|
|
37
56
|
import { utcTimestamp } from "./status.js";
|
|
38
57
|
|
|
39
|
-
/**
|
|
58
|
+
/**
|
|
59
|
+
* Legacy plan filename. Detection-only: {@link isPlanArtifactName} still
|
|
60
|
+
* accepts this exact name so plans published before named artifacts existed
|
|
61
|
+
* keep working. It is NEVER freshly emitted — a titleless plan now falls back
|
|
62
|
+
* to a bare `<hash>.plan.md` (see {@link planArtifactName}).
|
|
63
|
+
*/
|
|
40
64
|
export const PLAN_ARTIFACT_NAME = "plan.md";
|
|
41
65
|
|
|
42
66
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
67
|
+
* Suffix every named plan artifact carries. The UI keys plan detection on this
|
|
68
|
+
* suffix, so it must stay in sync with the SDK's `PLAN_ARTIFACT_SUFFIX`
|
|
69
|
+
* (`sdk/react/src/library/detect-plan-artifact.ts`). The two cannot share a
|
|
70
|
+
* module — the runner and the browser SDK have disjoint module graphs — so the
|
|
71
|
+
* constant is duplicated by design, mirroring {@link PLAN_ARTIFACT_NAME}.
|
|
72
|
+
*/
|
|
73
|
+
export const PLAN_ARTIFACT_SUFFIX = ".plan.md";
|
|
74
|
+
|
|
75
|
+
/** Longest slug we derive from a plan title before the `_<id>.plan.md` tail. */
|
|
76
|
+
const MAX_PLAN_SLUG_LENGTH = 60;
|
|
77
|
+
|
|
78
|
+
/** Hex length of the content-hash discriminator appended to named plans. */
|
|
79
|
+
const PLAN_ID_LENGTH = 8;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Reports whether an artifact filename is a plan: the legacy exact name, or any
|
|
83
|
+
* `*.plan.md`. Kept in sync with the SDK's `isPlanArtifactName`.
|
|
46
84
|
*/
|
|
47
|
-
export
|
|
85
|
+
export function isPlanArtifactName(name: string): boolean {
|
|
86
|
+
return name === PLAN_ARTIFACT_NAME || name.endsWith(PLAN_ARTIFACT_SUFFIX);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Plan-title extraction, mirrored from the SDK so the runner's derived filename
|
|
90
|
+
// and the card's displayed title agree on one title from one source (the plan's
|
|
91
|
+
// leading `# H1`). These three patterns are a verbatim copy of
|
|
92
|
+
// `sdk/react/src/internal/markdown-components.tsx`
|
|
93
|
+
// (`ENCLOSING_MARKDOWN_FENCE_RE`, `ENCLOSING_BARE_FENCE_RE`, `LEADING_H1_RE`)
|
|
94
|
+
// and MUST stay in sync with it — a fence-wrapped plan whose title the card
|
|
95
|
+
// unwraps must slug to that same title here, never to the fallback.
|
|
96
|
+
const ENCLOSING_MARKDOWN_FENCE_RE =
|
|
97
|
+
/^(`{3,})[ \t]*(?:markdown|md)[ \t]*\r?\n([\s\S]*?)\r?\n\1[ \t]*$/i;
|
|
98
|
+
const ENCLOSING_BARE_FENCE_RE = /^(`{3,})[ \t]*\r?\n([\s\S]*?)\r?\n\1[ \t]*$/;
|
|
99
|
+
const LEADING_H1_RE = /^#[ \t]+(.+?)[ \t]*(?:\r?\n+|$)/;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* The plan's title: the leading `# H1` of the plan text, after the same
|
|
103
|
+
* plan-scoped enclosing-fence unwrap (tagged ```markdown``` or a bare ``` `)
|
|
104
|
+
* the document renderers apply. `undefined` when the plan has no leading H1.
|
|
105
|
+
*/
|
|
106
|
+
function extractPlanTitle(planText: string): string | undefined {
|
|
107
|
+
const trimmed = planText.trim();
|
|
108
|
+
let body = trimmed;
|
|
109
|
+
const tagged = ENCLOSING_MARKDOWN_FENCE_RE.exec(trimmed);
|
|
110
|
+
if (tagged) {
|
|
111
|
+
body = tagged[2];
|
|
112
|
+
} else {
|
|
113
|
+
const bare = ENCLOSING_BARE_FENCE_RE.exec(trimmed);
|
|
114
|
+
if (bare) body = bare[2];
|
|
115
|
+
}
|
|
116
|
+
const h1 = LEADING_H1_RE.exec(body.trim());
|
|
117
|
+
return h1 ? h1[1] : undefined;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Strips a leading "Plan" LABEL from a title, e.g. `Plan: Create X` -> `Create
|
|
122
|
+
* X`. The separator (`:` or a dash) is REQUIRED: this removes a redundant label
|
|
123
|
+
* (a plan document already announces itself via the `.plan.md` suffix and the
|
|
124
|
+
* Plan card framing) without ever clipping a real title word — a bare `\bplan\b`
|
|
125
|
+
* would wrongly turn "Plan card UX cleanup" into "card UX cleanup".
|
|
126
|
+
*
|
|
127
|
+
* Deliberately runner/filename-only and NOT mirrored into the SDK's title
|
|
128
|
+
* extraction: display surfaces render the message's own `# H1` faithfully
|
|
129
|
+
* (`extractLeadingH1` is general-purpose and render-time-only), so the clean
|
|
130
|
+
* title is fixed at the source — the plan-mode prompt tells the model not to
|
|
131
|
+
* prefix titles with "Plan:". This strip is the durable-artifact safety net for
|
|
132
|
+
* when the model (or the enforcement-less Cursor harness) drifts.
|
|
133
|
+
*/
|
|
134
|
+
function stripPlanLabel(title: string): string {
|
|
135
|
+
return title.replace(/^plan\s*[:\u2013\u2014-]\s*/i, "");
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Slugifies a plan title into a filename-safe stem: lowercase, every run of
|
|
140
|
+
* non-alphanumerics collapsed to `-`, trimmed of leading/trailing `-`, and
|
|
141
|
+
* capped at {@link MAX_PLAN_SLUG_LENGTH}. Returns `""` for a title with no
|
|
142
|
+
* alphanumerics (e.g. only punctuation), which selects the fallback name.
|
|
143
|
+
*/
|
|
144
|
+
function slugifyPlanTitle(title: string): string {
|
|
145
|
+
return title
|
|
146
|
+
.toLowerCase()
|
|
147
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
148
|
+
.replace(/^-+|-+$/g, "")
|
|
149
|
+
.slice(0, MAX_PLAN_SLUG_LENGTH)
|
|
150
|
+
.replace(/-+$/g, "");
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Derives the plan artifact's filename from its text: `<slug>_<id>.plan.md`
|
|
155
|
+
* when the plan opens with a titled `# H1`, else a bare `<id>.plan.md`. The
|
|
156
|
+
* `<id>` is the first {@link PLAN_ID_LENGTH} hex of the content's SHA-256 — a
|
|
157
|
+
* user-facing discriminator for the shared download/list basename namespace,
|
|
158
|
+
* not a storage-uniqueness device (see the module doc).
|
|
159
|
+
*/
|
|
160
|
+
export function planArtifactName(planText: string): string {
|
|
161
|
+
const id = createHash("sha256")
|
|
162
|
+
.update(planText, "utf-8")
|
|
163
|
+
.digest("hex")
|
|
164
|
+
.slice(0, PLAN_ID_LENGTH);
|
|
165
|
+
const title = extractPlanTitle(planText);
|
|
166
|
+
const slug = title ? slugifyPlanTitle(stripPlanLabel(title)) : "";
|
|
167
|
+
return slug.length > 0
|
|
168
|
+
? `${slug}_${id}${PLAN_ARTIFACT_SUFFIX}`
|
|
169
|
+
: `${id}${PLAN_ARTIFACT_SUFFIX}`;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Sandbox path recorded on the artifact for a given filename. Routes under
|
|
174
|
+
* `.stigmer/` (the session platform dir), so it never pollutes the user's
|
|
175
|
+
* workspace, and a follow-up execution can reference it via workspace file
|
|
176
|
+
* refs if desired.
|
|
177
|
+
*/
|
|
178
|
+
export function planArtifactSandboxPath(name: string): string {
|
|
179
|
+
return `.stigmer/plans/${name}`;
|
|
180
|
+
}
|
|
48
181
|
|
|
49
182
|
/**
|
|
50
183
|
* Returns the text of the last AI message in a completed status, trimmed.
|
|
@@ -62,9 +195,11 @@ export function extractFinalPlanText(status: AgentExecutionStatus): string | und
|
|
|
62
195
|
}
|
|
63
196
|
|
|
64
197
|
/**
|
|
65
|
-
* Publishes `planText` as a
|
|
66
|
-
*
|
|
67
|
-
*
|
|
198
|
+
* Publishes `planText` as a plan ExecutionArtifact (named from its title —
|
|
199
|
+
* see {@link planArtifactName}) and registers it on `status.artifacts`.
|
|
200
|
+
* Idempotent: re-publishing replaces any existing plan artifact — matched by
|
|
201
|
+
* {@link isPlanArtifactName}, not exact name, so a re-plan whose title changed
|
|
202
|
+
* still supersedes rather than appends — preserving a single source of truth.
|
|
68
203
|
*
|
|
69
204
|
* Fire-and-forget by contract: a plan that fails to upload must never fail the
|
|
70
205
|
* execution. Errors are logged and swallowed.
|
|
@@ -84,13 +219,14 @@ export async function publishPlanArtifact(opts: {
|
|
|
84
219
|
try {
|
|
85
220
|
const content = Buffer.from(planText, "utf-8");
|
|
86
221
|
const contentHash = createHash("sha256").update(content).digest("hex");
|
|
87
|
-
const
|
|
222
|
+
const name = planArtifactName(planText);
|
|
223
|
+
const storageKey = `artifacts/${executionId}/${name}`;
|
|
88
224
|
|
|
89
225
|
await artifactStorage.upload(storageKey, content, "text/markdown");
|
|
90
226
|
|
|
91
227
|
const artifact = create(ExecutionArtifactSchema, {
|
|
92
|
-
name
|
|
93
|
-
sandboxPath:
|
|
228
|
+
name,
|
|
229
|
+
sandboxPath: planArtifactSandboxPath(name),
|
|
94
230
|
kind: ExecutionArtifactKind.FILE,
|
|
95
231
|
sizeBytes: BigInt(content.length),
|
|
96
232
|
storageKey,
|
|
@@ -98,7 +234,7 @@ export async function publishPlanArtifact(opts: {
|
|
|
98
234
|
contentHash,
|
|
99
235
|
});
|
|
100
236
|
|
|
101
|
-
const existingIdx = status.artifacts.findIndex((a) => a.name
|
|
237
|
+
const existingIdx = status.artifacts.findIndex((a) => isPlanArtifactName(a.name));
|
|
102
238
|
if (existingIdx >= 0) {
|
|
103
239
|
status.artifacts[existingIdx] = artifact;
|
|
104
240
|
} else {
|
|
@@ -106,7 +242,7 @@ export async function publishPlanArtifact(opts: {
|
|
|
106
242
|
}
|
|
107
243
|
|
|
108
244
|
console.log(
|
|
109
|
-
`[plan-artifact] execution=${executionId} — published ${
|
|
245
|
+
`[plan-artifact] execution=${executionId} — published ${name} ` +
|
|
110
246
|
`(${content.length} bytes, hash=${contentHash.slice(0, 12)})`,
|
|
111
247
|
);
|
|
112
248
|
} catch (err) {
|
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Plan mode's output contract spans three components that must agree:
|
|
5
5
|
* - the model produces the plan as its FINAL message (this directive),
|
|
6
|
-
* - the runner publishes that final message verbatim as a
|
|
7
|
-
* (`plan-artifact.ts` —
|
|
6
|
+
* - the runner publishes that final message verbatim as a plan markdown
|
|
7
|
+
* artifact, named from the plan's title (`plan-artifact.ts` —
|
|
8
|
+
* `extractFinalPlanText`, `planArtifactName`),
|
|
8
9
|
* - the SDK promotes the same message to a first-class plan document in the
|
|
9
10
|
* thread and offers "Build from plan".
|
|
10
11
|
*
|
|
@@ -25,8 +26,9 @@
|
|
|
25
26
|
/**
|
|
26
27
|
* Directive body injected into the system prompt of every Plan-mode
|
|
27
28
|
* execution. Deliberately explicit about the deliverable's shape: the final
|
|
28
|
-
* message is published verbatim as
|
|
29
|
-
*
|
|
29
|
+
* message is published verbatim as a plan document (whose filename is derived
|
|
30
|
+
* from the leading `#` title), so a fenced or chat-suffixed plan degrades the
|
|
31
|
+
* reviewable document the user sees.
|
|
30
32
|
*/
|
|
31
33
|
export const PLAN_MODE_DIRECTIVE = [
|
|
32
34
|
"IMPORTANT: You are in Plan mode — a read-only analysis turn whose " +
|
|
@@ -38,10 +40,13 @@ export const PLAN_MODE_DIRECTIVE = [
|
|
|
38
40
|
"- Only read, search, and analyze.",
|
|
39
41
|
"",
|
|
40
42
|
"Deliverable — your FINAL message IS the plan. It is published verbatim " +
|
|
41
|
-
"as a
|
|
43
|
+
"as a plan document that the user reviews and builds from, so:",
|
|
42
44
|
"- Write it as a complete, well-structured markdown document: start with " +
|
|
43
45
|
"a single `#` title and organize the work under `##` section headings. " +
|
|
44
46
|
"Use lists and tables where they aid scanning.",
|
|
47
|
+
'- Give the `#` title a concise, descriptive name for the work itself; do ' +
|
|
48
|
+
'NOT prefix it with "Plan:" (this document is already a plan — the ' +
|
|
49
|
+
"prefix is redundant and leaks into the plan's filename).",
|
|
45
50
|
"- Reference concrete file paths and describe the specific changes " +
|
|
46
51
|
"planned for each.",
|
|
47
52
|
"- Do NOT wrap the document in a code fence.",
|