@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
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mid-run live capture — the harness-agnostic glue that turns a content-free git
|
|
3
|
+
* delta ({@link ./git-substrate.js} `captureProgressDelta`) into the transient
|
|
4
|
+
* `AgentExecutionStatus.file_change_progress` snapshot the "N files changed so
|
|
5
|
+
* far" strip renders (DD-32).
|
|
6
|
+
*
|
|
7
|
+
* THE MODEL
|
|
8
|
+
* ---------
|
|
9
|
+
* This is category 2 of the two status patterns: a runner-owned, latest-snapshot
|
|
10
|
+
* DISPLAY field, NOT the event-sourced file-review ledger. It is deliberately NOT
|
|
11
|
+
* a `FileChangeSet` — progress is never in the ledger, carries NO file bytes or
|
|
12
|
+
* digests, and is NEVER decidable. The turn-boundary CANDIDATE_CAPTURED (in
|
|
13
|
+
* `file_change_sets`) remains the single authoritative, reviewable diff; a mid-run
|
|
14
|
+
* snapshot is no more authoritative than a streamed tool-call arg.
|
|
15
|
+
*
|
|
16
|
+
* Both harnesses drive this through {@link captureFileChangeProgress} from their
|
|
17
|
+
* per-persist loop, each passing its OWN `excludePaths` (the runner-owned gate
|
|
18
|
+
* files it writes into the workspace), so progress and the turn-boundary candidate
|
|
19
|
+
* agree on what is "the agent's change". Capture is throttled by a floor +
|
|
20
|
+
* tree-sha short-circuit so a quiet turn is nearly free.
|
|
21
|
+
*
|
|
22
|
+
* SECRET SAFETY
|
|
23
|
+
* -------------
|
|
24
|
+
* No file bodies are ever carried. A secret-like path ({@link isSecretLikePath})
|
|
25
|
+
* is still surfaced (path visible) but with its line counts ZEROED — the same
|
|
26
|
+
* "path visible, content withheld" rule the ledger uses (DD-12). Nothing new can
|
|
27
|
+
* leak through this field.
|
|
28
|
+
*
|
|
29
|
+
* @since File-Change HITL Redesign (mid-run live capture / DD-32)
|
|
30
|
+
*/
|
|
31
|
+
import { create } from "@bufbuild/protobuf";
|
|
32
|
+
import { FileChangeProgressEntrySchema, FileChangeProgressSchema, } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/filereview_pb";
|
|
33
|
+
import { utcTimestamp } from "../status.js";
|
|
34
|
+
import { toFileChangeKind } from "./capture.js";
|
|
35
|
+
import { captureProgressDelta } from "./git-substrate.js";
|
|
36
|
+
import { isSecretLikePath } from "./secret-paths.js";
|
|
37
|
+
/**
|
|
38
|
+
* Cap the per-file entry list so a turn touching thousands of files does not
|
|
39
|
+
* bloat the persisted status (which rides Temporal / the store). `files_changed`
|
|
40
|
+
* and the aggregate counts stay honest over ALL files; the strip shows "… and K
|
|
41
|
+
* more" when the list is capped.
|
|
42
|
+
*/
|
|
43
|
+
export const PROGRESS_MAX_ENTRIES = 200;
|
|
44
|
+
/**
|
|
45
|
+
* Minimum wall-clock gap between two mid-run captures, in ms. A floor on cost:
|
|
46
|
+
* every capture stages the working tree (`write-tree`), so we bound how often
|
|
47
|
+
* that runs regardless of persist frequency. Env-tunable for large-repo
|
|
48
|
+
* deployments; defaults to 2s (feels live without hammering git).
|
|
49
|
+
*/
|
|
50
|
+
export const PROGRESS_CAPTURE_MIN_INTERVAL_MS = readMinIntervalMs();
|
|
51
|
+
function readMinIntervalMs() {
|
|
52
|
+
const raw = process.env.STIGMER_PROGRESS_CAPTURE_MIN_INTERVAL_MS;
|
|
53
|
+
if (!raw)
|
|
54
|
+
return 2000;
|
|
55
|
+
const n = Number.parseInt(raw, 10);
|
|
56
|
+
return Number.isFinite(n) && n >= 0 ? n : 2000;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Whether enough wall-clock has elapsed since the last capture to take another.
|
|
60
|
+
* Pure and separated for direct testing (mirrors `persist-decision.ts`). A
|
|
61
|
+
* `lastAtMs` of 0 (never captured) always passes.
|
|
62
|
+
*/
|
|
63
|
+
export function shouldCaptureProgress(lastAtMs, nowMs, minIntervalMs = PROGRESS_CAPTURE_MIN_INTERVAL_MS) {
|
|
64
|
+
return nowMs - lastAtMs >= minIntervalMs;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Build the transient {@link FileChangeProgress} message from a content-free git
|
|
68
|
+
* delta. Zeroes counts for secret-like paths (path visible, magnitude withheld),
|
|
69
|
+
* caps the entry list at {@link PROGRESS_MAX_ENTRIES} while keeping
|
|
70
|
+
* `files_changed`/aggregate counts honest over every file, and stamps
|
|
71
|
+
* `captured_at`. Pure and exported for direct testing.
|
|
72
|
+
*/
|
|
73
|
+
export function buildFileChangeProgress(delta, changeSetId) {
|
|
74
|
+
let filesChanged = 0;
|
|
75
|
+
let totalAdded = 0;
|
|
76
|
+
let totalRemoved = 0;
|
|
77
|
+
const entries = [];
|
|
78
|
+
for (const entry of delta.entries) {
|
|
79
|
+
filesChanged += 1;
|
|
80
|
+
// A secret-like path is surfaced (path visible) but its magnitude is withheld
|
|
81
|
+
// — counts zeroed, mirroring the ledger's "path visible, content withheld".
|
|
82
|
+
const secret = isSecretLikePath(entry.pathAfter || entry.pathBefore);
|
|
83
|
+
const linesAdded = secret ? 0 : entry.linesAdded;
|
|
84
|
+
const linesRemoved = secret ? 0 : entry.linesRemoved;
|
|
85
|
+
totalAdded += linesAdded;
|
|
86
|
+
totalRemoved += linesRemoved;
|
|
87
|
+
if (entries.length < PROGRESS_MAX_ENTRIES) {
|
|
88
|
+
entries.push(create(FileChangeProgressEntrySchema, {
|
|
89
|
+
pathBefore: entry.pathBefore,
|
|
90
|
+
pathAfter: entry.pathAfter,
|
|
91
|
+
kind: toFileChangeKind(entry.changeType),
|
|
92
|
+
linesAdded,
|
|
93
|
+
linesRemoved,
|
|
94
|
+
}));
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return create(FileChangeProgressSchema, {
|
|
98
|
+
changeSetId,
|
|
99
|
+
filesChanged,
|
|
100
|
+
linesAdded: totalAdded,
|
|
101
|
+
linesRemoved: totalRemoved,
|
|
102
|
+
entries,
|
|
103
|
+
capturedAt: utcTimestamp(),
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
/** A fresh per-turn progress state. */
|
|
107
|
+
export function newProgressCaptureState() {
|
|
108
|
+
return { lastAtMs: 0 };
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Capture-and-attach the live progress snapshot onto `status.file_change_progress`,
|
|
112
|
+
* throttled by the floor + tree-sha short-circuit. Mutates `status` and `state`
|
|
113
|
+
* in place; a no-op when the floor has not elapsed or the working tree is
|
|
114
|
+
* unchanged since the last capture. Content-free and secret-safe (see
|
|
115
|
+
* {@link buildFileChangeProgress}). Called by both harnesses from their per-persist
|
|
116
|
+
* loop; each passes its own `excludePaths`.
|
|
117
|
+
*
|
|
118
|
+
* The field is set even when the delta is now EMPTY (the agent reverted its own
|
|
119
|
+
* edits) so the strip reflects the reversion (it hides at zero) rather than
|
|
120
|
+
* showing a stale count — the server's presence-guarded merge would keep the
|
|
121
|
+
* stale value if the runner omitted the field.
|
|
122
|
+
*/
|
|
123
|
+
export async function captureFileChangeProgress(opts) {
|
|
124
|
+
const now = opts.nowMs ?? Date.now();
|
|
125
|
+
if (!shouldCaptureProgress(opts.state.lastAtMs, now))
|
|
126
|
+
return;
|
|
127
|
+
opts.state.lastAtMs = now;
|
|
128
|
+
const delta = await captureProgressDelta(opts.gitRoot, opts.executionId, opts.baselineTree, opts.excludePaths, opts.state.lastTreeSha);
|
|
129
|
+
if (!delta)
|
|
130
|
+
return; // working tree unchanged since the last capture
|
|
131
|
+
opts.state.lastTreeSha = delta.afterTree;
|
|
132
|
+
opts.status.fileChangeProgress = buildFileChangeProgress(delta, opts.changeSetId);
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=progress.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3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AAI,CAAC,KAAK,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC;IACrC,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,GAAG,CAAC;QAAE,OAAO;IAC7D,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,GAAG,CAAC;IAE1B,MAAM,KAAK,GAAG,MAAM,oBAAoB,CACtC,IAAI,CAAC,OAAO,EACZ,IAAI,CAAC,WAAW,EAChB,IAAI,CAAC,YAAY,EACjB,IAAI,CAAC,YAAY,EACjB,IAAI,CAAC,KAAK,CAAC,WAAW,CACvB,CAAC;IACF,IAAI,CAAC,KAAK;QAAE,OAAO,CAAC,gDAAgD;IAEpE,IAAI,CAAC,KAAK,CAAC,WAAW,GAAG,KAAK,CAAC,SAAS,CAAC;IACzC,IAAI,CAAC,MAAM,CAAC,kBAAkB,GAAG,uBAAuB,CAAC,KAAK,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;AACpF,CAAC"}
|
|
@@ -11,8 +11,9 @@
|
|
|
11
11
|
* The directive has two variants, chosen by whether the approved plan document
|
|
12
12
|
* actually materialized in the workspace:
|
|
13
13
|
* - Attached (the normal case): the client uploaded the approved plan text
|
|
14
|
-
* (edited or not) and attached it, mounted
|
|
15
|
-
* The directive points the model at
|
|
14
|
+
* (edited or not) and attached it, mounted under `.stigmer/inputs/` as the
|
|
15
|
+
* plan's own file (`<slug>_<id>.plan.md`). The directive points the model at
|
|
16
|
+
* that file and names it authoritative —
|
|
16
17
|
* the user may have refined the document after the plan turn, so the
|
|
17
18
|
* conversation's version can be stale.
|
|
18
19
|
* - Conversation-only (the client's upload failed): the directive falls back
|
|
@@ -25,8 +26,9 @@
|
|
|
25
26
|
*/
|
|
26
27
|
/**
|
|
27
28
|
* Find the approved plan document among the workspace paths the harness
|
|
28
|
-
* injected for this execution's attachments. Detection keys on the
|
|
29
|
-
*
|
|
29
|
+
* injected for this execution's attachments. Detection keys on the plan
|
|
30
|
+
* filename convention ({@link isPlanArtifactName} — the legacy `plan.md` or any
|
|
31
|
+
* `*.plan.md`), the same convention the UI uses to detect the plan artifact.
|
|
30
32
|
* Returns `undefined` when no plan attachment landed (upload failed, or the
|
|
31
33
|
* attachment itself failed to inject), which selects the conversation-only
|
|
32
34
|
* directive variant.
|
|
@@ -11,8 +11,9 @@
|
|
|
11
11
|
* The directive has two variants, chosen by whether the approved plan document
|
|
12
12
|
* actually materialized in the workspace:
|
|
13
13
|
* - Attached (the normal case): the client uploaded the approved plan text
|
|
14
|
-
* (edited or not) and attached it, mounted
|
|
15
|
-
* The directive points the model at
|
|
14
|
+
* (edited or not) and attached it, mounted under `.stigmer/inputs/` as the
|
|
15
|
+
* plan's own file (`<slug>_<id>.plan.md`). The directive points the model at
|
|
16
|
+
* that file and names it authoritative —
|
|
16
17
|
* the user may have refined the document after the plan turn, so the
|
|
17
18
|
* conversation's version can be stale.
|
|
18
19
|
* - Conversation-only (the client's upload failed): the directive falls back
|
|
@@ -23,17 +24,44 @@
|
|
|
23
24
|
* framing (XML-tag section for Cursor, markdown heading for the native
|
|
24
25
|
* harness).
|
|
25
26
|
*/
|
|
26
|
-
import {
|
|
27
|
+
import { isPlanArtifactName } from "./plan-artifact.js";
|
|
28
|
+
/**
|
|
29
|
+
* Progress-tracking instruction shared by both directive variants (Tier 3 of
|
|
30
|
+
* Plan mode — plan-driven build progress). The agent's own to-do tool is the
|
|
31
|
+
* single writer of `status.todos`, so instructing it to derive the list from
|
|
32
|
+
* the approved plan is the entire plan→progress linkage: the runner's todo
|
|
33
|
+
* extraction and the clients' todo renderers light up unchanged.
|
|
34
|
+
*
|
|
35
|
+
* Deliberately tool-agnostic ("your to-do list"): the Cursor harness exposes
|
|
36
|
+
* TodoWrite/updateTodos, the native harness write_todos, and each runtime
|
|
37
|
+
* already teaches the model its own tool.
|
|
38
|
+
*
|
|
39
|
+
* Wording constraint: this block rides BOTH variants, and the conversation-only
|
|
40
|
+
* variant is pinned by tests to never contain "plan.md" (it has no plan file
|
|
41
|
+
* to reference) — so say "the plan", never name the file.
|
|
42
|
+
*/
|
|
43
|
+
const TRACK_PROGRESS_INSTRUCTION = [
|
|
44
|
+
"Track your progress with your to-do list so the user can follow the " +
|
|
45
|
+
"build:",
|
|
46
|
+
"- Before you start, break the plan into a concrete, ordered to-do list — " +
|
|
47
|
+
"roughly one item per implementation step.",
|
|
48
|
+
"- As you work, keep it current: mark each item in progress when you " +
|
|
49
|
+
"begin it and completed when it is done.",
|
|
50
|
+
].join("\n");
|
|
27
51
|
/**
|
|
28
52
|
* Find the approved plan document among the workspace paths the harness
|
|
29
|
-
* injected for this execution's attachments. Detection keys on the
|
|
30
|
-
*
|
|
53
|
+
* injected for this execution's attachments. Detection keys on the plan
|
|
54
|
+
* filename convention ({@link isPlanArtifactName} — the legacy `plan.md` or any
|
|
55
|
+
* `*.plan.md`), the same convention the UI uses to detect the plan artifact.
|
|
31
56
|
* Returns `undefined` when no plan attachment landed (upload failed, or the
|
|
32
57
|
* attachment itself failed to inject), which selects the conversation-only
|
|
33
58
|
* directive variant.
|
|
34
59
|
*/
|
|
35
60
|
export function findApprovedPlanPath(attachmentPaths) {
|
|
36
|
-
return attachmentPaths.find((p) =>
|
|
61
|
+
return attachmentPaths.find((p) => {
|
|
62
|
+
const name = p.split("/").pop();
|
|
63
|
+
return name !== undefined && isPlanArtifactName(name);
|
|
64
|
+
});
|
|
37
65
|
}
|
|
38
66
|
/**
|
|
39
67
|
* Build the implement-plan directive body for a Build-from-plan execution.
|
|
@@ -54,6 +82,8 @@ export function buildImplementPlanDirective(planPath) {
|
|
|
54
82
|
"That document is the authoritative version of the plan — the user may " +
|
|
55
83
|
"have edited it after it was proposed, so where it differs from the " +
|
|
56
84
|
"conversation above, follow the document.",
|
|
85
|
+
"",
|
|
86
|
+
TRACK_PROGRESS_INSTRUCTION,
|
|
57
87
|
].join("\n");
|
|
58
88
|
}
|
|
59
89
|
return [
|
|
@@ -61,6 +91,8 @@ export function buildImplementPlanDirective(planPath) {
|
|
|
61
91
|
"APPROVED.",
|
|
62
92
|
"",
|
|
63
93
|
"Implement the plan proposed in the conversation above, step by step.",
|
|
94
|
+
"",
|
|
95
|
+
TRACK_PROGRESS_INSTRUCTION,
|
|
64
96
|
].join("\n");
|
|
65
97
|
}
|
|
66
98
|
//# sourceMappingURL=implement-plan-prompt.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"implement-plan-prompt.js","sourceRoot":"","sources":["../../src/shared/implement-plan-prompt.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"implement-plan-prompt.js","sourceRoot":"","sources":["../../src/shared/implement-plan-prompt.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAExD;;;;;;;;;;;;;;GAcG;AACH,MAAM,0BAA0B,GAAG;IACjC,sEAAsE;QACpE,QAAQ;IACV,2EAA2E;QACzE,2CAA2C;IAC7C,sEAAsE;QACpE,yCAAyC;CAC5C,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAEb;;;;;;;;GAQG;AACH,MAAM,UAAU,oBAAoB,CAClC,eAAkC;IAElC,OAAO,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE;QAChC,MAAM,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;QAChC,OAAO,IAAI,KAAK,SAAS,IAAI,kBAAkB,CAAC,IAAI,CAAC,CAAC;IACxD,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,2BAA2B,CAAC,QAAiB;IAC3D,IAAI,QAAQ,EAAE,CAAC;QACb,OAAO;YACL,mEAAmE;gBACjE,WAAW;YACb,EAAE;YACF,+CAA+C,QAAQ,cAAc;gBACnE,wCAAwC;YAC1C,EAAE;YACF,wEAAwE;gBACtE,qEAAqE;gBACrE,0CAA0C;YAC5C,EAAE;YACF,0BAA0B;SAC3B,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACf,CAAC;IAED,OAAO;QACL,mEAAmE;YACjE,WAAW;QACb,EAAE;QACF,sEAAsE;QACtE,EAAE;QACF,0BAA0B;KAC3B,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC"}
|
|
@@ -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,19 +40,46 @@
|
|
|
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
|
import type { AgentExecutionStatus } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/api_pb";
|
|
28
47
|
import type { ArtifactStorage } from "./artifact-storage.js";
|
|
29
|
-
/**
|
|
48
|
+
/**
|
|
49
|
+
* Legacy plan filename. Detection-only: {@link isPlanArtifactName} still
|
|
50
|
+
* accepts this exact name so plans published before named artifacts existed
|
|
51
|
+
* keep working. It is NEVER freshly emitted — a titleless plan now falls back
|
|
52
|
+
* to a bare `<hash>.plan.md` (see {@link planArtifactName}).
|
|
53
|
+
*/
|
|
30
54
|
export declare const PLAN_ARTIFACT_NAME = "plan.md";
|
|
31
55
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
56
|
+
* Suffix every named plan artifact carries. The UI keys plan detection on this
|
|
57
|
+
* suffix, so it must stay in sync with the SDK's `PLAN_ARTIFACT_SUFFIX`
|
|
58
|
+
* (`sdk/react/src/library/detect-plan-artifact.ts`). The two cannot share a
|
|
59
|
+
* module — the runner and the browser SDK have disjoint module graphs — so the
|
|
60
|
+
* constant is duplicated by design, mirroring {@link PLAN_ARTIFACT_NAME}.
|
|
61
|
+
*/
|
|
62
|
+
export declare const PLAN_ARTIFACT_SUFFIX = ".plan.md";
|
|
63
|
+
/**
|
|
64
|
+
* Reports whether an artifact filename is a plan: the legacy exact name, or any
|
|
65
|
+
* `*.plan.md`. Kept in sync with the SDK's `isPlanArtifactName`.
|
|
66
|
+
*/
|
|
67
|
+
export declare function isPlanArtifactName(name: string): boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Derives the plan artifact's filename from its text: `<slug>_<id>.plan.md`
|
|
70
|
+
* when the plan opens with a titled `# H1`, else a bare `<id>.plan.md`. The
|
|
71
|
+
* `<id>` is the first {@link PLAN_ID_LENGTH} hex of the content's SHA-256 — a
|
|
72
|
+
* user-facing discriminator for the shared download/list basename namespace,
|
|
73
|
+
* not a storage-uniqueness device (see the module doc).
|
|
74
|
+
*/
|
|
75
|
+
export declare function planArtifactName(planText: string): string;
|
|
76
|
+
/**
|
|
77
|
+
* Sandbox path recorded on the artifact for a given filename. Routes under
|
|
78
|
+
* `.stigmer/` (the session platform dir), so it never pollutes the user's
|
|
79
|
+
* workspace, and a follow-up execution can reference it via workspace file
|
|
80
|
+
* refs if desired.
|
|
35
81
|
*/
|
|
36
|
-
export declare
|
|
82
|
+
export declare function planArtifactSandboxPath(name: string): string;
|
|
37
83
|
/**
|
|
38
84
|
* Returns the text of the last AI message in a completed status, trimmed.
|
|
39
85
|
* Returns `undefined` when there is no AI message with content — the plan was
|
|
@@ -41,9 +87,11 @@ export declare const PLAN_ARTIFACT_SANDBOX_PATH = ".stigmer/plans/plan.md";
|
|
|
41
87
|
*/
|
|
42
88
|
export declare function extractFinalPlanText(status: AgentExecutionStatus): string | undefined;
|
|
43
89
|
/**
|
|
44
|
-
* Publishes `planText` as a
|
|
45
|
-
*
|
|
46
|
-
*
|
|
90
|
+
* Publishes `planText` as a plan ExecutionArtifact (named from its title —
|
|
91
|
+
* see {@link planArtifactName}) and registers it on `status.artifacts`.
|
|
92
|
+
* Idempotent: re-publishing replaces any existing plan artifact — matched by
|
|
93
|
+
* {@link isPlanArtifactName}, not exact name, so a re-plan whose title changed
|
|
94
|
+
* still supersedes rather than appends — preserving a single source of truth.
|
|
47
95
|
*
|
|
48
96
|
* Fire-and-forget by contract: a plan that fails to upload must never fail the
|
|
49
97
|
* execution. Errors are logged and swallowed.
|
|
@@ -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,22 +40,128 @@
|
|
|
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
|
import { createHash } from "node:crypto";
|
|
28
47
|
import { create } from "@bufbuild/protobuf";
|
|
29
48
|
import { ExecutionArtifactSchema } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/artifact_pb";
|
|
30
49
|
import { ExecutionArtifactKind, MessageType, } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/enum_pb";
|
|
31
50
|
import { utcTimestamp } from "./status.js";
|
|
32
|
-
/**
|
|
51
|
+
/**
|
|
52
|
+
* Legacy plan filename. Detection-only: {@link isPlanArtifactName} still
|
|
53
|
+
* accepts this exact name so plans published before named artifacts existed
|
|
54
|
+
* keep working. It is NEVER freshly emitted — a titleless plan now falls back
|
|
55
|
+
* to a bare `<hash>.plan.md` (see {@link planArtifactName}).
|
|
56
|
+
*/
|
|
33
57
|
export const PLAN_ARTIFACT_NAME = "plan.md";
|
|
34
58
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
59
|
+
* Suffix every named plan artifact carries. The UI keys plan detection on this
|
|
60
|
+
* suffix, so it must stay in sync with the SDK's `PLAN_ARTIFACT_SUFFIX`
|
|
61
|
+
* (`sdk/react/src/library/detect-plan-artifact.ts`). The two cannot share a
|
|
62
|
+
* module — the runner and the browser SDK have disjoint module graphs — so the
|
|
63
|
+
* constant is duplicated by design, mirroring {@link PLAN_ARTIFACT_NAME}.
|
|
38
64
|
*/
|
|
39
|
-
export const
|
|
65
|
+
export const PLAN_ARTIFACT_SUFFIX = ".plan.md";
|
|
66
|
+
/** Longest slug we derive from a plan title before the `_<id>.plan.md` tail. */
|
|
67
|
+
const MAX_PLAN_SLUG_LENGTH = 60;
|
|
68
|
+
/** Hex length of the content-hash discriminator appended to named plans. */
|
|
69
|
+
const PLAN_ID_LENGTH = 8;
|
|
70
|
+
/**
|
|
71
|
+
* Reports whether an artifact filename is a plan: the legacy exact name, or any
|
|
72
|
+
* `*.plan.md`. Kept in sync with the SDK's `isPlanArtifactName`.
|
|
73
|
+
*/
|
|
74
|
+
export function isPlanArtifactName(name) {
|
|
75
|
+
return name === PLAN_ARTIFACT_NAME || name.endsWith(PLAN_ARTIFACT_SUFFIX);
|
|
76
|
+
}
|
|
77
|
+
// Plan-title extraction, mirrored from the SDK so the runner's derived filename
|
|
78
|
+
// and the card's displayed title agree on one title from one source (the plan's
|
|
79
|
+
// leading `# H1`). These three patterns are a verbatim copy of
|
|
80
|
+
// `sdk/react/src/internal/markdown-components.tsx`
|
|
81
|
+
// (`ENCLOSING_MARKDOWN_FENCE_RE`, `ENCLOSING_BARE_FENCE_RE`, `LEADING_H1_RE`)
|
|
82
|
+
// and MUST stay in sync with it — a fence-wrapped plan whose title the card
|
|
83
|
+
// unwraps must slug to that same title here, never to the fallback.
|
|
84
|
+
const ENCLOSING_MARKDOWN_FENCE_RE = /^(`{3,})[ \t]*(?:markdown|md)[ \t]*\r?\n([\s\S]*?)\r?\n\1[ \t]*$/i;
|
|
85
|
+
const ENCLOSING_BARE_FENCE_RE = /^(`{3,})[ \t]*\r?\n([\s\S]*?)\r?\n\1[ \t]*$/;
|
|
86
|
+
const LEADING_H1_RE = /^#[ \t]+(.+?)[ \t]*(?:\r?\n+|$)/;
|
|
87
|
+
/**
|
|
88
|
+
* The plan's title: the leading `# H1` of the plan text, after the same
|
|
89
|
+
* plan-scoped enclosing-fence unwrap (tagged ```markdown``` or a bare ``` `)
|
|
90
|
+
* the document renderers apply. `undefined` when the plan has no leading H1.
|
|
91
|
+
*/
|
|
92
|
+
function extractPlanTitle(planText) {
|
|
93
|
+
const trimmed = planText.trim();
|
|
94
|
+
let body = trimmed;
|
|
95
|
+
const tagged = ENCLOSING_MARKDOWN_FENCE_RE.exec(trimmed);
|
|
96
|
+
if (tagged) {
|
|
97
|
+
body = tagged[2];
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
const bare = ENCLOSING_BARE_FENCE_RE.exec(trimmed);
|
|
101
|
+
if (bare)
|
|
102
|
+
body = bare[2];
|
|
103
|
+
}
|
|
104
|
+
const h1 = LEADING_H1_RE.exec(body.trim());
|
|
105
|
+
return h1 ? h1[1] : undefined;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Strips a leading "Plan" LABEL from a title, e.g. `Plan: Create X` -> `Create
|
|
109
|
+
* X`. The separator (`:` or a dash) is REQUIRED: this removes a redundant label
|
|
110
|
+
* (a plan document already announces itself via the `.plan.md` suffix and the
|
|
111
|
+
* Plan card framing) without ever clipping a real title word — a bare `\bplan\b`
|
|
112
|
+
* would wrongly turn "Plan card UX cleanup" into "card UX cleanup".
|
|
113
|
+
*
|
|
114
|
+
* Deliberately runner/filename-only and NOT mirrored into the SDK's title
|
|
115
|
+
* extraction: display surfaces render the message's own `# H1` faithfully
|
|
116
|
+
* (`extractLeadingH1` is general-purpose and render-time-only), so the clean
|
|
117
|
+
* title is fixed at the source — the plan-mode prompt tells the model not to
|
|
118
|
+
* prefix titles with "Plan:". This strip is the durable-artifact safety net for
|
|
119
|
+
* when the model (or the enforcement-less Cursor harness) drifts.
|
|
120
|
+
*/
|
|
121
|
+
function stripPlanLabel(title) {
|
|
122
|
+
return title.replace(/^plan\s*[:\u2013\u2014-]\s*/i, "");
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Slugifies a plan title into a filename-safe stem: lowercase, every run of
|
|
126
|
+
* non-alphanumerics collapsed to `-`, trimmed of leading/trailing `-`, and
|
|
127
|
+
* capped at {@link MAX_PLAN_SLUG_LENGTH}. Returns `""` for a title with no
|
|
128
|
+
* alphanumerics (e.g. only punctuation), which selects the fallback name.
|
|
129
|
+
*/
|
|
130
|
+
function slugifyPlanTitle(title) {
|
|
131
|
+
return title
|
|
132
|
+
.toLowerCase()
|
|
133
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
134
|
+
.replace(/^-+|-+$/g, "")
|
|
135
|
+
.slice(0, MAX_PLAN_SLUG_LENGTH)
|
|
136
|
+
.replace(/-+$/g, "");
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Derives the plan artifact's filename from its text: `<slug>_<id>.plan.md`
|
|
140
|
+
* when the plan opens with a titled `# H1`, else a bare `<id>.plan.md`. The
|
|
141
|
+
* `<id>` is the first {@link PLAN_ID_LENGTH} hex of the content's SHA-256 — a
|
|
142
|
+
* user-facing discriminator for the shared download/list basename namespace,
|
|
143
|
+
* not a storage-uniqueness device (see the module doc).
|
|
144
|
+
*/
|
|
145
|
+
export function planArtifactName(planText) {
|
|
146
|
+
const id = createHash("sha256")
|
|
147
|
+
.update(planText, "utf-8")
|
|
148
|
+
.digest("hex")
|
|
149
|
+
.slice(0, PLAN_ID_LENGTH);
|
|
150
|
+
const title = extractPlanTitle(planText);
|
|
151
|
+
const slug = title ? slugifyPlanTitle(stripPlanLabel(title)) : "";
|
|
152
|
+
return slug.length > 0
|
|
153
|
+
? `${slug}_${id}${PLAN_ARTIFACT_SUFFIX}`
|
|
154
|
+
: `${id}${PLAN_ARTIFACT_SUFFIX}`;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Sandbox path recorded on the artifact for a given filename. Routes under
|
|
158
|
+
* `.stigmer/` (the session platform dir), so it never pollutes the user's
|
|
159
|
+
* workspace, and a follow-up execution can reference it via workspace file
|
|
160
|
+
* refs if desired.
|
|
161
|
+
*/
|
|
162
|
+
export function planArtifactSandboxPath(name) {
|
|
163
|
+
return `.stigmer/plans/${name}`;
|
|
164
|
+
}
|
|
40
165
|
/**
|
|
41
166
|
* Returns the text of the last AI message in a completed status, trimmed.
|
|
42
167
|
* Returns `undefined` when there is no AI message with content — the plan was
|
|
@@ -52,9 +177,11 @@ export function extractFinalPlanText(status) {
|
|
|
52
177
|
return undefined;
|
|
53
178
|
}
|
|
54
179
|
/**
|
|
55
|
-
* Publishes `planText` as a
|
|
56
|
-
*
|
|
57
|
-
*
|
|
180
|
+
* Publishes `planText` as a plan ExecutionArtifact (named from its title —
|
|
181
|
+
* see {@link planArtifactName}) and registers it on `status.artifacts`.
|
|
182
|
+
* Idempotent: re-publishing replaces any existing plan artifact — matched by
|
|
183
|
+
* {@link isPlanArtifactName}, not exact name, so a re-plan whose title changed
|
|
184
|
+
* still supersedes rather than appends — preserving a single source of truth.
|
|
58
185
|
*
|
|
59
186
|
* Fire-and-forget by contract: a plan that fails to upload must never fail the
|
|
60
187
|
* execution. Errors are logged and swallowed.
|
|
@@ -67,25 +194,26 @@ export async function publishPlanArtifact(opts) {
|
|
|
67
194
|
try {
|
|
68
195
|
const content = Buffer.from(planText, "utf-8");
|
|
69
196
|
const contentHash = createHash("sha256").update(content).digest("hex");
|
|
70
|
-
const
|
|
197
|
+
const name = planArtifactName(planText);
|
|
198
|
+
const storageKey = `artifacts/${executionId}/${name}`;
|
|
71
199
|
await artifactStorage.upload(storageKey, content, "text/markdown");
|
|
72
200
|
const artifact = create(ExecutionArtifactSchema, {
|
|
73
|
-
name
|
|
74
|
-
sandboxPath:
|
|
201
|
+
name,
|
|
202
|
+
sandboxPath: planArtifactSandboxPath(name),
|
|
75
203
|
kind: ExecutionArtifactKind.FILE,
|
|
76
204
|
sizeBytes: BigInt(content.length),
|
|
77
205
|
storageKey,
|
|
78
206
|
createdAt: utcTimestamp(),
|
|
79
207
|
contentHash,
|
|
80
208
|
});
|
|
81
|
-
const existingIdx = status.artifacts.findIndex((a) => a.name
|
|
209
|
+
const existingIdx = status.artifacts.findIndex((a) => isPlanArtifactName(a.name));
|
|
82
210
|
if (existingIdx >= 0) {
|
|
83
211
|
status.artifacts[existingIdx] = artifact;
|
|
84
212
|
}
|
|
85
213
|
else {
|
|
86
214
|
status.artifacts.push(artifact);
|
|
87
215
|
}
|
|
88
|
-
console.log(`[plan-artifact] execution=${executionId} — published ${
|
|
216
|
+
console.log(`[plan-artifact] execution=${executionId} — published ${name} ` +
|
|
89
217
|
`(${content.length} bytes, hash=${contentHash.slice(0, 12)})`);
|
|
90
218
|
}
|
|
91
219
|
catch (err) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plan-artifact.js","sourceRoot":"","sources":["../../src/shared/plan-artifact.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"plan-artifact.js","sourceRoot":"","sources":["../../src/shared/plan-artifact.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,OAAO,EAAE,uBAAuB,EAAE,MAAM,kEAAkE,CAAC;AAC3G,OAAO,EACL,qBAAqB,EACrB,WAAW,GACZ,MAAM,8DAA8D,CAAC;AAEtE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,SAAS,CAAC;AAE5C;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,UAAU,CAAC;AAE/C,gFAAgF;AAChF,MAAM,oBAAoB,GAAG,EAAE,CAAC;AAEhC,4EAA4E;AAC5E,MAAM,cAAc,GAAG,CA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AAI,CAAC,EAAE,CAAC;YACrB,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC,GAAG,QAAQ,CAAC;QAC3C,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAClC,CAAC;QAED,OAAO,CAAC,GAAG,CACT,6BAA6B,WAAW,gBAAgB,IAAI,GAAG;YAC/D,IAAI,OAAO,CAAC,MAAM,gBAAgB,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAC9D,CAAC;IACJ,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,IAAI,CACV,6BAA6B,WAAW,KAAK;YAC7C,uCAAuC,GAAG,EAAE,CAC7C,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -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
|
*
|
|
@@ -24,7 +25,8 @@
|
|
|
24
25
|
/**
|
|
25
26
|
* Directive body injected into the system prompt of every Plan-mode
|
|
26
27
|
* execution. Deliberately explicit about the deliverable's shape: the final
|
|
27
|
-
* message is published verbatim as
|
|
28
|
-
*
|
|
28
|
+
* message is published verbatim as a plan document (whose filename is derived
|
|
29
|
+
* from the leading `#` title), so a fenced or chat-suffixed plan degrades the
|
|
30
|
+
* reviewable document the user sees.
|
|
29
31
|
*/
|
|
30
32
|
export declare const PLAN_MODE_DIRECTIVE: string;
|