@bastani/atomic 0.8.22-0 → 0.8.23-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +38 -0
- package/dist/builtin/intercom/CHANGELOG.md +6 -0
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/mcp/CHANGELOG.md +6 -0
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/CHANGELOG.md +13 -0
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/web-access/CHANGELOG.md +6 -0
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/builtin/workflows/CHANGELOG.md +35 -0
- package/dist/builtin/workflows/README.md +31 -12
- package/dist/builtin/workflows/builtin/goal.ts +139 -100
- package/dist/builtin/workflows/builtin/ralph.ts +137 -182
- package/dist/builtin/workflows/package.json +1 -1
- package/dist/builtin/workflows/src/extension/index.ts +2 -4
- package/dist/builtin/workflows/src/tui/stage-chat-view.ts +110 -13
- package/dist/builtin/workflows/src/tui/workflow-attach-pane.ts +2 -2
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +8 -4
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tools/ask-user-question/ask-user-question.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/ask-user-question.js +31 -11
- package/dist/core/tools/ask-user-question/ask-user-question.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host.d.ts +8 -0
- package/dist/modes/interactive/components/chat-session-host.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host.js +83 -2
- package/dist/modes/interactive/components/chat-session-host.js.map +1 -1
- package/dist/modes/interactive/components/chat-transcript.d.ts +12 -1
- package/dist/modes/interactive/components/chat-transcript.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-transcript.js +140 -13
- package/dist/modes/interactive/components/chat-transcript.js.map +1 -1
- package/dist/modes/interactive/components/index.d.ts +1 -1
- package/dist/modes/interactive/components/index.d.ts.map +1 -1
- package/dist/modes/interactive/components/index.js.map +1 -1
- package/docs/workflows.md +66 -17
- package/package.json +1 -1
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* - **Escape** mirrors the main coding-agent chat interrupt path for active
|
|
23
23
|
* live stages: it requests a controlled pause/abort while keeping the
|
|
24
24
|
* composer active. While paused, Enter calls `handle.resume(text)`.
|
|
25
|
-
* - **Ctrl+D** detaches (back to graph),
|
|
25
|
+
* - **Ctrl+D** detaches (back to graph), including while paused;
|
|
26
26
|
* **Escape** closes the popup when idle.
|
|
27
27
|
* - **Blocked** stage: keystrokes absorbed; BLOCKED banner names the
|
|
28
28
|
* upstream awaiter.
|
|
@@ -69,7 +69,7 @@ import type { StageControlHandle } from "../runs/foreground/stage-control-regist
|
|
|
69
69
|
import { isKeybindingsLike, type KeybindingsLike } from "./keybindings-adapter.js";
|
|
70
70
|
import { BOLD, RESET, hexBg, hexToAnsi, lerpColor } from "./color-utils.js";
|
|
71
71
|
import { renderWorkflowNoticeCard, type WorkflowNoticeTone } from "./workflow-notice-card.js";
|
|
72
|
-
import { Key, matchesKey, visibleWidth } from "./text-helpers.js";
|
|
72
|
+
import { Key, matchesKey, truncateToWidth, visibleWidth } from "./text-helpers.js";
|
|
73
73
|
import {
|
|
74
74
|
fitStageChatFrame,
|
|
75
75
|
planStageChatFrame,
|
|
@@ -105,7 +105,7 @@ export interface StageChatViewOpts {
|
|
|
105
105
|
* inspect-only (settled stage with no live handle).
|
|
106
106
|
*/
|
|
107
107
|
handle?: StageControlHandle;
|
|
108
|
-
/** Called when the user presses Ctrl+D
|
|
108
|
+
/** Called when the user presses Ctrl+D (back to graph). */
|
|
109
109
|
onDetach: (reason?: StageChatDetachReason, metadata?: StageChatDetachMetadata) => void;
|
|
110
110
|
/** Called when the user presses Escape (close the whole popup). */
|
|
111
111
|
onClose: () => void;
|
|
@@ -678,7 +678,9 @@ export class StageChatView implements Component, Focusable {
|
|
|
678
678
|
const workingLines = chatChromeHidden ? [] : this.chatHost.renderWorkingStatus(w);
|
|
679
679
|
const usageLines = chatChromeHidden ? [] : this.chatHost.renderUsage(w);
|
|
680
680
|
const editorLines = chatChromeHidden ? [] : this.chatHost.renderEditor(w);
|
|
681
|
-
const footerLines = chatChromeHidden
|
|
681
|
+
const footerLines = chatChromeHidden
|
|
682
|
+
? []
|
|
683
|
+
: this._renderFooterWithOrchestratorReturnHint(w, this.chatHost.renderFooter(w));
|
|
682
684
|
|
|
683
685
|
const totalRows = this._viewLineCount();
|
|
684
686
|
const plan = planStageChatFrame({
|
|
@@ -704,7 +706,9 @@ export class StageChatView implements Component, Focusable {
|
|
|
704
706
|
if (blocked) this.chatHost.scrollToBottom();
|
|
705
707
|
|
|
706
708
|
let bodyLines: string[];
|
|
707
|
-
if (
|
|
709
|
+
if (bodyBudget <= 0) {
|
|
710
|
+
bodyLines = [];
|
|
711
|
+
} else if (promptActive) {
|
|
708
712
|
bodyLines = this._renderPromptBody(w, bodyBudget);
|
|
709
713
|
} else if (blocked) {
|
|
710
714
|
bodyLines = this._renderBlockedBody(w, bodyBudget, stage);
|
|
@@ -778,6 +782,67 @@ export class StageChatView implements Component, Focusable {
|
|
|
778
782
|
return hexToAnsi(this.theme.borderDim) + "─".repeat(width) + RESET;
|
|
779
783
|
}
|
|
780
784
|
|
|
785
|
+
private _renderFooterWithOrchestratorReturnHint(
|
|
786
|
+
width: number,
|
|
787
|
+
footerLines: readonly string[],
|
|
788
|
+
): string[] {
|
|
789
|
+
if (footerLines.length === 0) {
|
|
790
|
+
return [this._mergeOrchestratorReturnHintIntoLine("", width)];
|
|
791
|
+
}
|
|
792
|
+
const lines = [...footerLines];
|
|
793
|
+
const lastIndex = lines.length - 1;
|
|
794
|
+
lines[lastIndex] = this._mergeOrchestratorReturnHintIntoLine(
|
|
795
|
+
lines[lastIndex] ?? "",
|
|
796
|
+
width,
|
|
797
|
+
);
|
|
798
|
+
return lines;
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
private _embedOrchestratorReturnHintInWidget(
|
|
802
|
+
widgetLines: readonly string[],
|
|
803
|
+
width: number,
|
|
804
|
+
): string[] {
|
|
805
|
+
if (widgetLines.length === 0) {
|
|
806
|
+
return [this._mergeOrchestratorReturnHintIntoLine("", width)];
|
|
807
|
+
}
|
|
808
|
+
const lines = [...widgetLines];
|
|
809
|
+
const targetIndex = widgetHintTargetLineIndex(lines);
|
|
810
|
+
lines[targetIndex] = this._mergeOrchestratorReturnHintIntoLine(
|
|
811
|
+
lines[targetIndex] ?? "",
|
|
812
|
+
width,
|
|
813
|
+
{ preserveTrailingBorder: true, rightMargin: 2 },
|
|
814
|
+
);
|
|
815
|
+
return lines;
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
private _mergeOrchestratorReturnHintIntoLine(
|
|
819
|
+
line: string,
|
|
820
|
+
width: number,
|
|
821
|
+
options: { preserveTrailingBorder?: boolean; rightMargin?: number } = {},
|
|
822
|
+
): string {
|
|
823
|
+
const plain = "ctrl+d returns to orchestrator panel";
|
|
824
|
+
const styled =
|
|
825
|
+
paint("ctrl+d", this.theme.text, { bold: true }) +
|
|
826
|
+
paint(" returns to orchestrator panel", this.theme.textMuted);
|
|
827
|
+
const trailingBorder = options.preserveTrailingBorder === true
|
|
828
|
+
? trailingWidgetBorderChar(line)
|
|
829
|
+
: "";
|
|
830
|
+
const suffixWidth = visibleWidth(trailingBorder);
|
|
831
|
+
const hintWidth = visibleWidth(plain);
|
|
832
|
+
const requestedRightMargin = Math.max(
|
|
833
|
+
0,
|
|
834
|
+
Math.floor(options.rightMargin ?? 0),
|
|
835
|
+
);
|
|
836
|
+
const rightMargin = Math.min(
|
|
837
|
+
requestedRightMargin,
|
|
838
|
+
Math.max(0, width - suffixWidth - hintWidth),
|
|
839
|
+
);
|
|
840
|
+
const hintStart = Math.max(0, width - suffixWidth - rightMargin - hintWidth);
|
|
841
|
+
const prefix = truncateToWidth(line, hintStart, "", true);
|
|
842
|
+
const gap = Math.max(0, hintStart - visibleWidth(prefix));
|
|
843
|
+
return prefix + " ".repeat(gap) + styled + " ".repeat(rightMargin) + trailingBorder;
|
|
844
|
+
}
|
|
845
|
+
|
|
781
846
|
// -------------------------------------------------------------------------
|
|
782
847
|
// Body — welcome panel / banner + transcript / blocked
|
|
783
848
|
// -------------------------------------------------------------------------
|
|
@@ -913,7 +978,7 @@ export class StageChatView implements Component, Focusable {
|
|
|
913
978
|
"warning",
|
|
914
979
|
"❚❚",
|
|
915
980
|
"PAUSED",
|
|
916
|
-
"enter resumes · ctrl+d
|
|
981
|
+
"enter resumes · ctrl+d graph",
|
|
917
982
|
),
|
|
918
983
|
);
|
|
919
984
|
callout.push(
|
|
@@ -981,12 +1046,18 @@ export class StageChatView implements Component, Focusable {
|
|
|
981
1046
|
const component = this.mountedCustomUi?.component;
|
|
982
1047
|
if (!component) return [];
|
|
983
1048
|
setComponentFocused(component, this.focused);
|
|
984
|
-
return component.render(width);
|
|
1049
|
+
return this._embedOrchestratorReturnHintInWidget(component.render(width), width);
|
|
985
1050
|
}
|
|
986
1051
|
|
|
987
1052
|
private _renderPromptBody(width: number, budget: number): string[] {
|
|
988
1053
|
const primitiveLines = this._renderPrimitivePromptBody(width);
|
|
989
|
-
if (primitiveLines)
|
|
1054
|
+
if (primitiveLines) {
|
|
1055
|
+
return this._fitPromptBodyLines(
|
|
1056
|
+
this._embedOrchestratorReturnHintInWidget(primitiveLines, width),
|
|
1057
|
+
width,
|
|
1058
|
+
budget,
|
|
1059
|
+
);
|
|
1060
|
+
}
|
|
990
1061
|
|
|
991
1062
|
const state = this.promptState;
|
|
992
1063
|
const lines = state
|
|
@@ -997,7 +1068,11 @@ export class StageChatView implements Component, Focusable {
|
|
|
997
1068
|
cursorOn: this.focused,
|
|
998
1069
|
})
|
|
999
1070
|
: [];
|
|
1000
|
-
return this._fitPromptBodyLines(
|
|
1071
|
+
return this._fitPromptBodyLines(
|
|
1072
|
+
this._embedOrchestratorReturnHintInWidget(lines, width),
|
|
1073
|
+
width,
|
|
1074
|
+
budget,
|
|
1075
|
+
);
|
|
1001
1076
|
}
|
|
1002
1077
|
|
|
1003
1078
|
private _renderPrimitivePromptBody(width: number): string[] | null {
|
|
@@ -1203,8 +1278,7 @@ export class StageChatView implements Component, Focusable {
|
|
|
1203
1278
|
// stays pending (the stage remains awaiting_input) and is re-displayed
|
|
1204
1279
|
// when the user re-attaches.
|
|
1205
1280
|
this._releaseMountedCustomUi();
|
|
1206
|
-
|
|
1207
|
-
else this.onDetach();
|
|
1281
|
+
this.onDetach();
|
|
1208
1282
|
return true;
|
|
1209
1283
|
}
|
|
1210
1284
|
if (matchesKey(data, Key.ctrl("c"))) {
|
|
@@ -1233,8 +1307,7 @@ export class StageChatView implements Component, Focusable {
|
|
|
1233
1307
|
const readOnlyPromptArchive = readOnlyArchive && stage?.promptFootprint !== undefined;
|
|
1234
1308
|
if (matchesKey(data, Key.ctrl("d"))) {
|
|
1235
1309
|
if (!this.promptState && this.chatHost.hasInputText()) return this.chatHost.handleInput(data);
|
|
1236
|
-
|
|
1237
|
-
else this.onDetach();
|
|
1310
|
+
this.onDetach();
|
|
1238
1311
|
return true;
|
|
1239
1312
|
}
|
|
1240
1313
|
if (this.promptState) {
|
|
@@ -1337,6 +1410,7 @@ export class StageChatView implements Component, Focusable {
|
|
|
1337
1410
|
}
|
|
1338
1411
|
|
|
1339
1412
|
invalidate(): void {
|
|
1413
|
+
this.chatHost.invalidate();
|
|
1340
1414
|
this._syncPromptState(this._currentStage()?.pendingPrompt);
|
|
1341
1415
|
}
|
|
1342
1416
|
|
|
@@ -1699,6 +1773,29 @@ function takeRows(lines: readonly string[], rows: number): string[] {
|
|
|
1699
1773
|
return lines.slice(0, rows);
|
|
1700
1774
|
}
|
|
1701
1775
|
|
|
1776
|
+
function widgetHintTargetLineIndex(lines: readonly string[]): number {
|
|
1777
|
+
for (let index = lines.length - 1; index >= 0; index -= 1) {
|
|
1778
|
+
if (!isWidgetBottomBorderLine(lines[index] ?? "")) return index;
|
|
1779
|
+
}
|
|
1780
|
+
return Math.max(0, lines.length - 1);
|
|
1781
|
+
}
|
|
1782
|
+
|
|
1783
|
+
function isWidgetBottomBorderLine(line: string): boolean {
|
|
1784
|
+
const plain = stripAnsi(line).trim();
|
|
1785
|
+
const chars = Array.from(plain);
|
|
1786
|
+
if (chars.length < 2) return false;
|
|
1787
|
+
const first = chars[0] ?? "";
|
|
1788
|
+
const last = chars.at(-1) ?? "";
|
|
1789
|
+
if (!"╰└+".includes(first) || !"╯┘+".includes(last)) return false;
|
|
1790
|
+
return chars.slice(1, -1).every((char) => "─═- ".includes(char));
|
|
1791
|
+
}
|
|
1792
|
+
|
|
1793
|
+
function trailingWidgetBorderChar(line: string): string {
|
|
1794
|
+
const plain = stripAnsi(line).trimEnd();
|
|
1795
|
+
const last = Array.from(plain).at(-1) ?? "";
|
|
1796
|
+
return "╯┘┤┴│|+".includes(last) ? last : "";
|
|
1797
|
+
}
|
|
1798
|
+
|
|
1702
1799
|
interface PaintOpts {
|
|
1703
1800
|
bold?: boolean;
|
|
1704
1801
|
italic?: boolean;
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* between the orchestrator `GraphView` and a stage-scoped
|
|
6
6
|
* `StageChatView`. Pressing Enter on a graph node attaches the popup
|
|
7
7
|
* to that node's chat; Ctrl+D in chat mode swaps back to graph mode
|
|
8
|
-
* with the same node still focused (see ui/attach-mockup.html),
|
|
9
|
-
* paused stage chats
|
|
8
|
+
* with the same node still focused (see ui/attach-mockup.html), including
|
|
9
|
+
* paused stage chats.
|
|
10
10
|
*
|
|
11
11
|
* The shell never remounts the overlay — it only flips a `mode`
|
|
12
12
|
* field and re-renders, so the popup stays in pi-tui's overlay layer
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"system-prompt.d.ts","sourceRoot":"","sources":["../../src/core/system-prompt.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAyB,KAAK,KAAK,EAAE,MAAM,aAAa,CAAC;AAWhE,MAAM,WAAW,iBAAiB;IAChC,kDAAkD;IAClD,QAAQ,EAAE,MAAM,CAAC;IACjB,iDAAiD;IACjD,EAAE,EAAE,MAAM,CAAC;IACX,iDAAiD;IACjD,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,wBAAwB;IACvC,+CAA+C;IAC/C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,8FAA8F;IAC9F,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,wFAAwF;IACxF,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,0DAA0D;IAC1D,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,qFAAqF;IACrF,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,uCAAuC;IACvC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,yBAAyB;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,sEAAsE;IACtE,aAAa,CAAC,EAAE,iBAAiB,CAAC;IAClC,+DAA+D;IAC/D,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,gCAAgC;IAChC,YAAY,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACxD,yBAAyB;IACzB,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC;CAClB;AAED,kEAAkE;AAClE,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,GAAG,MAAM,CA0M3E","sourcesContent":["/**\n * System prompt construction and project context loading\n */\n\nimport { getDocsPath, getExamplesPath, getReadmePath } from \"../config.ts\";\nimport { formatSkillsForPrompt, type Skill } from \"./skills.ts\";\n\nconst DEFAULT_PROMPT_TOOLS = [\n \"read\",\n \"bash\",\n \"edit\",\n \"write\",\n \"ask_user_question\",\n \"todo\",\n] as const;\n\nexport interface SystemPromptModel {\n /** Provider identifier for the selected model. */\n provider: string;\n /** Stable provider-specific model identifier. */\n id: string;\n /** Human-readable model name, when available. */\n name?: string;\n}\n\nexport interface BuildSystemPromptOptions {\n /** Custom system prompt (replaces default). */\n customPrompt?: string;\n /** Tools to include in prompt. Default: [read, bash, edit, write, ask_user_question, todo] */\n selectedTools?: string[];\n /** Tool names explicitly excluded by the caller and omitted from generated guidance. */\n excludedTools?: string[];\n /** Optional one-line tool snippets keyed by tool name. */\n toolSnippets?: Record<string, string>;\n /** Additional guideline bullets appended to the default system prompt guidelines. */\n promptGuidelines?: string[];\n /** Text to append to system prompt. */\n appendSystemPrompt?: string;\n /** Working directory. */\n cwd: string;\n /** Currently selected model, used for model-aware prompt metadata. */\n selectedModel?: SystemPromptModel;\n /** Current reasoning/thinking level for the selected model. */\n selectedThinkingLevel?: string;\n /** Pre-loaded context files. */\n contextFiles?: Array<{ path: string; content: string }>;\n /** Pre-loaded skills. */\n skills?: Skill[];\n}\n\n/** Build the system prompt with tools, guidelines, and context */\nexport function buildSystemPrompt(options: BuildSystemPromptOptions): string {\n const {\n customPrompt,\n selectedTools,\n excludedTools,\n toolSnippets,\n promptGuidelines,\n appendSystemPrompt,\n cwd,\n selectedModel,\n selectedThinkingLevel,\n contextFiles: providedContextFiles,\n skills: providedSkills,\n } = options;\n const resolvedCwd = cwd;\n const promptCwd = resolvedCwd.replace(/\\\\/g, \"/\");\n\n const now = new Date();\n const year = now.getFullYear();\n const month = String(now.getMonth() + 1).padStart(2, \"0\");\n const day = String(now.getDate()).padStart(2, \"0\");\n const date = `${year}-${month}-${day}`;\n\n const appendSection = appendSystemPrompt ? `\\n\\n${appendSystemPrompt}` : \"\";\n const modelName =\n selectedModel?.name?.trim() || selectedModel?.id || \"unknown\";\n const modelReasoningLevel = selectedThinkingLevel?.trim() || \"off\";\n\n const contextFiles = providedContextFiles ?? [];\n const skills = providedSkills ?? [];\n const explicitlyExcludedTools = new Set(excludedTools ?? []);\n const isPromptToolAvailable = (name: string): boolean =>\n (!selectedTools || selectedTools.includes(name)) &&\n !explicitlyExcludedTools.has(name);\n\n if (customPrompt) {\n let prompt = customPrompt;\n\n if (appendSection) {\n prompt += appendSection;\n }\n\n // Append project context files\n if (contextFiles.length > 0) {\n prompt += \"\\n\\n# Project Context\\n\\n\";\n prompt += \"Project-specific instructions and guidelines:\\n\\n\";\n for (const { path: filePath, content } of contextFiles) {\n prompt += `<context_file path=\\\"${filePath}\\\">\\n${content}\\n</context_file>\\n\\n`;\n }\n }\n\n // Append skills section (only if read tool is available)\n if (isPromptToolAvailable(\"read\") && skills.length > 0) {\n prompt += formatSkillsForPrompt(skills);\n }\n\n // Add model metadata, date, and working directory last\n prompt += `\\nModel name (used for commit attribution): ${modelName}`;\n prompt += `\\nModel reasoning level: ${modelReasoningLevel}`;\n prompt += `\\nCurrent date: ${date}`;\n prompt += `\\nCurrent working directory: ${promptCwd}`;\n\n return prompt;\n }\n\n // Get absolute paths to documentation and examples\n const readmePath = getReadmePath();\n const docsPath = getDocsPath();\n const examplesPath = getExamplesPath();\n\n // Build tools list based on selected tools.\n // A tool appears in Available tools only when the caller provides a one-line snippet.\n const tools = (selectedTools ?? DEFAULT_PROMPT_TOOLS).filter(\n (name) => !explicitlyExcludedTools.has(name),\n );\n const visibleTools = tools.filter((name) => !!toolSnippets?.[name]);\n const toolsList =\n visibleTools.length > 0\n ? visibleTools\n .map((name) => `- ${name}: ${toolSnippets![name]}`)\n .join(\"\\n\")\n : \"(none)\";\n\n // Build guidelines based on which tools are actually available\n const guidelinesList: string[] = [];\n const guidelinesSet = new Set<string>();\n const addGuideline = (guideline: string): void => {\n if (guidelinesSet.has(guideline)) {\n return;\n }\n guidelinesSet.add(guideline);\n guidelinesList.push(guideline);\n };\n\n const hasBash = tools.includes(\"bash\");\n const hasGrep = tools.includes(\"grep\");\n const hasFind = tools.includes(\"find\");\n const hasLs = tools.includes(\"ls\");\n const hasRead = tools.includes(\"read\");\n\n // File exploration guidelines\n if (hasBash && !hasGrep && !hasFind && !hasLs) {\n addGuideline(\"Use bash for file operations like ls, rg, find\");\n } else if (hasBash && (hasGrep || hasFind || hasLs)) {\n addGuideline(\n \"Prefer grep/find/ls tools over bash for file exploration (faster, respects .gitignore)\",\n );\n }\n\n for (const guideline of promptGuidelines ?? []) {\n const normalized = guideline.trim();\n if (normalized.length > 0) {\n addGuideline(normalized);\n }\n }\n\n // Always include these\n addGuideline(\"Be concise in your responses\");\n addGuideline(\"Show file paths clearly when working with files\");\n\n const guidelines = guidelinesList.map((g) => `- ${g}`).join(\"\\n\");\n\n const askUserQuestionGuidance = explicitlyExcludedTools.has(\n \"ask_user_question\",\n )\n ? \"\"\n : \"- Always ask clarifying questions if the user's request is ambiguous or lacks necessary details. NEVER make assumptions about what the user wants. If you find yourself circling in thought and asking what the user \\\"really\\\" wants, stop and ask the user for clarification using the ask_user_question tool if available. It's better to clarify intent rather than to guess.\\n- **Asking the user is a strict requirement**: Whenever you need to ask the user anything — a clarification, a decision, a choice between options, a confirmation, or any yes/no question — you MUST ask it by calling the `ask_user_question` tool. Never pose a question to the user as plain assistant text. Every question you direct to the user goes through `ask_user_question`; writing the question in prose instead of calling the tool is not allowed.\";\n const todoGuidance = explicitlyExcludedTools.has(\"todo\")\n ? \"\"\n : \"- **To-do management**: If the user has a complex task that can be broken down into actionable steps, use the `todo` tool to create a task list before proceeding. This ensures clarity and alignment with the user's goals and that you have a way to track your work and ensure you are meeting the user's expectations.\";\n\n const subagentGuidance = explicitlyExcludedTools.has(\"subagent\")\n ? \"\"\n : `- **Subagent Orchestration**:\n - To avoid draining your context window, prefer to use subagents for complex tasks all non-trivial operations should be delegated to subagents.\n - You should delegate running bash commands (particularly ones that are likely to produce lots of output) such as investigating with the \\`aws\\` CLI, using the \\`gh\\` CLI, digging through logs to \\`bash\\` subagents.\n - You should use separate subagents for separate tasks, and you may launch them in parallel, but do not delegate multiple tasks that are likely to have significant overlap to separate subagents.\n - Sometimes subagents will take a long time. DO NOT attempt to do the job yourself while waiting for the subagent to respond Instead, use the time to plan out your next steps.\n - **Debugging**: When a user asks about debugging, spawn a debugger subagent first.\n - Do not attempt to debug or analyze code yourself without first consulting the debugger subagent.\n - Explain the debugger's insights to the user clearly and concisely.\n - Once the user confirms, implement the necessary code changes based on those insights.\n - If the user has follow-up questions, spawn additional debugger and research subagents as needed.`;\n\n const workflowGuidance = explicitlyExcludedTools.has(\"workflow\")\n ? \"\"\n : `- **Workflows**: Use the \\`workflow\\` tool for existing named workflows and for repeatable, inspectable, resumable, or multi-stage processes; use direct \\`task\\`, \\`tasks\\`, or \\`chain\\` workflow calls for one-off tracked work when that is useful.\n - For unfamiliar named workflows, discover with \\`action: \"list\"\\`, inspect with \\`action: \"get\"\\` or \\`action: \"inputs\"\\`, and run with \\`action: \"run\"\\`, \\`workflow\\`, and validated \\`inputs\\`; do not invent workflow names or input keys.\n - Monitor long-running workflow runs through lifecycle notices and targeted \\`status\\`/\\`stages\\`/\\`stage\\` checks when you need new information; do not micro-manage every stage or create sleep/status polling loops.\n - Use run-control and messaging actions (\\`send\\`, \\`pause\\`, \\`resume\\`, \\`interrupt\\`, \\`kill\\`) only when needed to answer prompts, steer a stage, resume or interrupt paused work, or respond to user requests/control signals.\n - For transcripts, avoid reading whole session transcripts at once. Use \\`stages\\` or \\`stage\\` to get \\`sessionFile\\`/\\`transcriptPath\\`, quote the exact path without rewriting separators (preserve Windows backslashes), search it with \\`rg\\`/\\`grep\\`, and read small relevant ranges; use \\`transcript\\` with explicit \\`tail\\` or \\`limit\\` only for quick recent-context checks.\n - If a user asks to create or edit a workflow, use the create-spec skill when available and ask detailed clarifying questions until you understand its purpose, inputs, stages, handoffs, validation, and success criteria. Then read the workflow docs/examples and implement the workflow from the created spec directly as a TypeScript definition.\n - If you run \\`ralph\\` or \\`goal\\`, define an objective that includes tight scope, concrete and verifiable done criteria, and validation steps; then monitor progress as above instead of doing parallel implementation yourself.`;\n\n let prompt = `You are an expert coding assistant operating named Atomic, a coding agent harness. You help users by reading files, executing commands, editing code, and writing new files.\n\nAvailable tools:\n${toolsList}\n\nIn addition to the tools above, you may have access to other custom tools depending on the project.\n\nGuidelines:\n${guidelines}\n${askUserQuestionGuidance}\n${todoGuidance}\n${subagentGuidance}\n${workflowGuidance}\n\nAtomic documentation (read only when the user asks about customizing Atomic itself, its SDK, creating workflows, packages, extensions, themes, skills, or TUI):\n- Main documentation: ${readmePath}\n- Additional docs: ${docsPath}\n- Examples: ${examplesPath} (extensions, custom tools, SDK)\n- Docs/examples references above must be resolved against these absolute roots; e.g. docs/foo.md means ${docsPath}/foo.md and examples/bar means ${examplesPath}/bar.\n- When asked about: atomic workflows (docs/workflows.md), extensions (docs/extensions.md, examples/extensions/), themes (docs/themes.md), skills (docs/skills.md), prompt templates (docs/prompt-templates.md), TUI components (docs/tui.md), keybindings (docs/keybindings.md), SDK integrations (docs/sdk.md), custom providers (docs/custom-provider.md), adding models (docs/models.md), atomic packages (docs/packages.md)\n- When working on Atomic topics, read the docs and examples, and follow .md cross-references before implementing\n- Always read Atomic .md files completely and follow links to related docs (e.g., tui.md for TUI API details)`;\n\n if (appendSection) {\n prompt += appendSection;\n }\n\n // Append project context files\n if (contextFiles.length > 0) {\n prompt += \"\\n\\n# Project Context\\n\\n\";\n prompt += \"Project-specific instructions and guidelines:\\n\\n\";\n for (const { path: filePath, content } of contextFiles) {\n prompt += `<context_file path=\\\"${filePath}\\\">\\n${content}\\n</context_file>\\n\\n`;\n }\n }\n\n // Append skills section (only if read tool is available)\n if (hasRead && skills.length > 0) {\n prompt += formatSkillsForPrompt(skills);\n }\n\n // Add model metadata, date, and working directory last\n prompt += `\\nModel name (used for commit attribution): ${modelName}`;\n prompt += `\\nModel reasoning level: ${modelReasoningLevel}`;\n prompt += `\\nCurrent date: ${date}`;\n prompt += `\\nCurrent working directory: ${promptCwd}`;\n\n return prompt;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"system-prompt.d.ts","sourceRoot":"","sources":["../../src/core/system-prompt.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAyB,KAAK,KAAK,EAAE,MAAM,aAAa,CAAC;AAWhE,MAAM,WAAW,iBAAiB;IAChC,kDAAkD;IAClD,QAAQ,EAAE,MAAM,CAAC;IACjB,iDAAiD;IACjD,EAAE,EAAE,MAAM,CAAC;IACX,iDAAiD;IACjD,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,wBAAwB;IACvC,+CAA+C;IAC/C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,8FAA8F;IAC9F,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,wFAAwF;IACxF,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,0DAA0D;IAC1D,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,qFAAqF;IACrF,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,uCAAuC;IACvC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,yBAAyB;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,sEAAsE;IACtE,aAAa,CAAC,EAAE,iBAAiB,CAAC;IAClC,+DAA+D;IAC/D,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,gCAAgC;IAChC,YAAY,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACxD,yBAAyB;IACzB,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC;CAClB;AAED,kEAAkE;AAClE,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,GAAG,MAAM,CA8M3E","sourcesContent":["/**\n * System prompt construction and project context loading\n */\n\nimport { getDocsPath, getExamplesPath, getReadmePath } from \"../config.ts\";\nimport { formatSkillsForPrompt, type Skill } from \"./skills.ts\";\n\nconst DEFAULT_PROMPT_TOOLS = [\n \"read\",\n \"bash\",\n \"edit\",\n \"write\",\n \"ask_user_question\",\n \"todo\",\n] as const;\n\nexport interface SystemPromptModel {\n /** Provider identifier for the selected model. */\n provider: string;\n /** Stable provider-specific model identifier. */\n id: string;\n /** Human-readable model name, when available. */\n name?: string;\n}\n\nexport interface BuildSystemPromptOptions {\n /** Custom system prompt (replaces default). */\n customPrompt?: string;\n /** Tools to include in prompt. Default: [read, bash, edit, write, ask_user_question, todo] */\n selectedTools?: string[];\n /** Tool names explicitly excluded by the caller and omitted from generated guidance. */\n excludedTools?: string[];\n /** Optional one-line tool snippets keyed by tool name. */\n toolSnippets?: Record<string, string>;\n /** Additional guideline bullets appended to the default system prompt guidelines. */\n promptGuidelines?: string[];\n /** Text to append to system prompt. */\n appendSystemPrompt?: string;\n /** Working directory. */\n cwd: string;\n /** Currently selected model, used for model-aware prompt metadata. */\n selectedModel?: SystemPromptModel;\n /** Current reasoning/thinking level for the selected model. */\n selectedThinkingLevel?: string;\n /** Pre-loaded context files. */\n contextFiles?: Array<{ path: string; content: string }>;\n /** Pre-loaded skills. */\n skills?: Skill[];\n}\n\n/** Build the system prompt with tools, guidelines, and context */\nexport function buildSystemPrompt(options: BuildSystemPromptOptions): string {\n const {\n customPrompt,\n selectedTools,\n excludedTools,\n toolSnippets,\n promptGuidelines,\n appendSystemPrompt,\n cwd,\n selectedModel,\n selectedThinkingLevel,\n contextFiles: providedContextFiles,\n skills: providedSkills,\n } = options;\n const resolvedCwd = cwd;\n const promptCwd = resolvedCwd.replace(/\\\\/g, \"/\");\n\n const now = new Date();\n const year = now.getFullYear();\n const month = String(now.getMonth() + 1).padStart(2, \"0\");\n const day = String(now.getDate()).padStart(2, \"0\");\n const date = `${year}-${month}-${day}`;\n\n const appendSection = appendSystemPrompt ? `\\n\\n${appendSystemPrompt}` : \"\";\n const modelName =\n selectedModel?.name?.trim() || selectedModel?.id || \"unknown\";\n const modelReasoningLevel = selectedThinkingLevel?.trim() || \"off\";\n\n const contextFiles = providedContextFiles ?? [];\n const skills = providedSkills ?? [];\n const explicitlyExcludedTools = new Set(excludedTools ?? []);\n const isPromptToolAvailable = (name: string): boolean =>\n (!selectedTools || selectedTools.includes(name)) &&\n !explicitlyExcludedTools.has(name);\n\n if (customPrompt) {\n let prompt = customPrompt;\n\n if (appendSection) {\n prompt += appendSection;\n }\n\n // Append project context files\n if (contextFiles.length > 0) {\n prompt += \"\\n\\n# Project Context\\n\\n\";\n prompt += \"Project-specific instructions and guidelines:\\n\\n\";\n for (const { path: filePath, content } of contextFiles) {\n prompt += `<context_file path=\\\"${filePath}\\\">\\n${content}\\n</context_file>\\n\\n`;\n }\n }\n\n // Append skills section (only if read tool is available)\n if (isPromptToolAvailable(\"read\") && skills.length > 0) {\n prompt += formatSkillsForPrompt(skills);\n }\n\n // Add model metadata, date, and working directory last\n prompt += `\\nModel name (used for commit attribution): ${modelName}`;\n prompt += `\\nModel reasoning level: ${modelReasoningLevel}`;\n prompt += `\\nCurrent date: ${date}`;\n prompt += `\\nCurrent working directory: ${promptCwd}`;\n\n return prompt;\n }\n\n // Get absolute paths to documentation and examples\n const readmePath = getReadmePath();\n const docsPath = getDocsPath();\n const examplesPath = getExamplesPath();\n\n // Build tools list based on selected tools.\n // A tool appears in Available tools only when the caller provides a one-line snippet.\n const tools = (selectedTools ?? DEFAULT_PROMPT_TOOLS).filter(\n (name) => !explicitlyExcludedTools.has(name),\n );\n const visibleTools = tools.filter((name) => !!toolSnippets?.[name]);\n const toolsList =\n visibleTools.length > 0\n ? visibleTools\n .map((name) => `- ${name}: ${toolSnippets![name]}`)\n .join(\"\\n\")\n : \"(none)\";\n\n // Build guidelines based on which tools are actually available\n const guidelinesList: string[] = [];\n const guidelinesSet = new Set<string>();\n const addGuideline = (guideline: string): void => {\n if (guidelinesSet.has(guideline)) {\n return;\n }\n guidelinesSet.add(guideline);\n guidelinesList.push(guideline);\n };\n\n const hasBash = tools.includes(\"bash\");\n const hasGrep = tools.includes(\"grep\");\n const hasFind = tools.includes(\"find\");\n const hasLs = tools.includes(\"ls\");\n const hasRead = tools.includes(\"read\");\n\n // File exploration guidelines\n if (hasBash && !hasGrep && !hasFind && !hasLs) {\n addGuideline(\"Use bash for file operations like ls, rg, find\");\n } else if (hasBash && (hasGrep || hasFind || hasLs)) {\n addGuideline(\n \"Prefer grep/find/ls tools over bash for file exploration (faster, respects .gitignore)\",\n );\n }\n\n for (const guideline of promptGuidelines ?? []) {\n const normalized = guideline.trim();\n if (normalized.length > 0) {\n addGuideline(normalized);\n }\n }\n\n // Always include these\n addGuideline(\"Be concise in your responses\");\n addGuideline(\"Show file paths clearly when working with files\");\n\n const guidelines = guidelinesList.map((g) => `- ${g}`).join(\"\\n\");\n\n const askUserQuestionGuidance = explicitlyExcludedTools.has(\n \"ask_user_question\",\n )\n ? \"\"\n : \"- Always ask clarifying questions if the user's request is ambiguous or lacks necessary details. NEVER make assumptions about what the user wants. If you find yourself circling in thought and asking what the user \\\"really\\\" wants, stop and ask the user for clarification using the ask_user_question tool if available. It's better to clarify intent rather than to guess.\\n- **Asking the user is a strict requirement**: Whenever you need to ask the user anything — a clarification, a decision, a choice between options, a confirmation, or any yes/no question — you MUST ask it by calling the `ask_user_question` tool. Never pose a question to the user as plain assistant text. Every question you direct to the user goes through `ask_user_question`; writing the question in prose instead of calling the tool is not allowed.\";\n const todoGuidance = explicitlyExcludedTools.has(\"todo\")\n ? \"\"\n : \"- **To-do management**: If the user has a complex task that can be broken down into actionable steps, use the `todo` tool to create a task list before proceeding. This ensures clarity and alignment with the user's goals and that you have a way to track your work and ensure you are meeting the user's expectations.\";\n\n const subagentGuidance = explicitlyExcludedTools.has(\"subagent\")\n ? \"\"\n : `- **Subagent Orchestration**:\n - To avoid draining your context window, prefer to use subagents for complex tasks all non-trivial operations should be delegated to subagents.\n - You should delegate running bash commands (particularly ones that are likely to produce lots of output) such as investigating with the \\`aws\\` CLI, using the \\`gh\\` CLI, digging through logs to \\`bash\\` subagents.\n - You should use separate subagents for separate tasks, and you may launch them in parallel, but do not delegate multiple tasks that are likely to have significant overlap to separate subagents.\n - Sometimes subagents will take a long time. DO NOT attempt to do the job yourself while waiting for the subagent to respond Instead, use the time to plan out your next steps.\n - **Debugging**: When a user asks about debugging, spawn a debugger subagent first.\n - Do not attempt to debug or analyze code yourself without first consulting the debugger subagent.\n - Explain the debugger's insights to the user clearly and concisely.\n - Once the user confirms, implement the necessary code changes based on those insights.\n - If the user has follow-up questions, spawn additional debugger and research subagents as needed.`;\n\n const workflowGuidance = explicitlyExcludedTools.has(\"workflow\")\n ? \"\"\n : `- **Workflows**: Use the \\`workflow\\` tool for existing named workflows and for repeatable, inspectable, resumable, or multi-stage processes; use direct \\`task\\`, \\`tasks\\`, or \\`chain\\` workflow calls for one-off tracked work when that is useful.\n - For unfamiliar named workflows, discover with \\`action: \"list\"\\`, inspect with \\`action: \"get\"\\` or \\`action: \"inputs\"\\`, and run with \\`action: \"run\"\\`, \\`workflow\\`, and validated \\`inputs\\`; do not invent workflow names or input keys.\n - Once you run a workflow with the workflow tool, end your current turn and wait for the next user input or lifecycle notice.\n - You will automatically be alerted of key lifecycle events like start, finish, failure; do not attempt to track its progress yourself or read its logs or stages unless the user asks you to or you need to check in on it to get information for the next step.\n - If the user needs information from the workflow run, use \\`status\\`, \\`stages\\`, or \\`stage\\` calls to get targeted information instead of trying to read everything.\n - Offer to help the user on another task instead of anxiously polling or help the user run another workflow if they need.\n - Use run-control and messaging actions (\\`send\\`, \\`pause\\`, \\`resume\\`, \\`interrupt\\`, \\`kill\\`) only when needed to answer prompts, steer a stage, resume or interrupt paused work, or respond to user requests/control signals.\n - For transcripts, avoid reading whole session transcripts at once. Use \\`stages\\` or \\`stage\\` to get \\`sessionFile\\`/\\`transcriptPath\\`, quote the exact path without rewriting separators (preserve Windows backslashes), search it with \\`rg\\`/\\`grep\\`, and read small relevant ranges; use \\`transcript\\` with explicit \\`tail\\` or \\`limit\\` only for quick recent-context checks.\n - If a user asks to create or edit a workflow, use the create-spec skill when available and ask detailed clarifying questions until you understand its purpose, inputs, stages, handoffs, validation, and success criteria. Then read the workflow docs/examples and implement the workflow from the created spec directly as a TypeScript definition. After you implement the workflow, reload it to access it and run it with test inputs to validate it works as intended before presenting it to the user.\n - Tip: when designing workflows, implement it in a way that you pass information from stage to stage by writing it to a file or artifact (either deterministic or model-driven), pass the path with \\`reads\\`, and explicitly prompt the downstream agent with wording like \\`Read the file at <path>...\\`; do not inject large \\`previous\\` payloads or session history into the next prompt unless explicitly requested to.\n - If you run \\`ralph\\` or \\`goal\\` workflow, define an objective that includes tight scope, concrete and verifiable done criteria, and validation steps; then monitor progress as above instead of doing parallel implementation yourself.`;\n\n let prompt = `You are an expert coding assistant operating named Atomic, a coding agent harness. You help users by reading files, executing commands, editing code, and writing new files.\n\nAvailable tools:\n${toolsList}\n\nIn addition to the tools above, you may have access to other custom tools depending on the project.\n\nGuidelines:\n${guidelines}\n${askUserQuestionGuidance}\n${todoGuidance}\n${subagentGuidance}\n${workflowGuidance}\n\nAtomic documentation (read only when the user asks about customizing Atomic itself, its SDK, creating workflows, packages, extensions, themes, skills, or TUI):\n- Main documentation: ${readmePath}\n- Additional docs: ${docsPath}\n- Examples: ${examplesPath} (extensions, custom tools, SDK)\n- Docs/examples references above must be resolved against these absolute roots; e.g. docs/foo.md means ${docsPath}/foo.md and examples/bar means ${examplesPath}/bar.\n- When asked about: atomic workflows (docs/workflows.md), extensions (docs/extensions.md, examples/extensions/), themes (docs/themes.md), skills (docs/skills.md), prompt templates (docs/prompt-templates.md), TUI components (docs/tui.md), keybindings (docs/keybindings.md), SDK integrations (docs/sdk.md), custom providers (docs/custom-provider.md), adding models (docs/models.md), atomic packages (docs/packages.md)\n- When working on Atomic topics, read the docs and examples, and follow .md cross-references before implementing\n- Always read Atomic .md files completely and follow links to related docs (e.g., tui.md for TUI API details)`;\n\n if (appendSection) {\n prompt += appendSection;\n }\n\n // Append project context files\n if (contextFiles.length > 0) {\n prompt += \"\\n\\n# Project Context\\n\\n\";\n prompt += \"Project-specific instructions and guidelines:\\n\\n\";\n for (const { path: filePath, content } of contextFiles) {\n prompt += `<context_file path=\\\"${filePath}\\\">\\n${content}\\n</context_file>\\n\\n`;\n }\n }\n\n // Append skills section (only if read tool is available)\n if (hasRead && skills.length > 0) {\n prompt += formatSkillsForPrompt(skills);\n }\n\n // Add model metadata, date, and working directory last\n prompt += `\\nModel name (used for commit attribution): ${modelName}`;\n prompt += `\\nModel reasoning level: ${modelReasoningLevel}`;\n prompt += `\\nCurrent date: ${date}`;\n prompt += `\\nCurrent working directory: ${promptCwd}`;\n\n return prompt;\n}\n"]}
|
|
@@ -120,11 +120,15 @@ export function buildSystemPrompt(options) {
|
|
|
120
120
|
? ""
|
|
121
121
|
: `- **Workflows**: Use the \`workflow\` tool for existing named workflows and for repeatable, inspectable, resumable, or multi-stage processes; use direct \`task\`, \`tasks\`, or \`chain\` workflow calls for one-off tracked work when that is useful.
|
|
122
122
|
- For unfamiliar named workflows, discover with \`action: "list"\`, inspect with \`action: "get"\` or \`action: "inputs"\`, and run with \`action: "run"\`, \`workflow\`, and validated \`inputs\`; do not invent workflow names or input keys.
|
|
123
|
-
-
|
|
124
|
-
|
|
123
|
+
- Once you run a workflow with the workflow tool, end your current turn and wait for the next user input or lifecycle notice.
|
|
124
|
+
- You will automatically be alerted of key lifecycle events like start, finish, failure; do not attempt to track its progress yourself or read its logs or stages unless the user asks you to or you need to check in on it to get information for the next step.
|
|
125
|
+
- If the user needs information from the workflow run, use \`status\`, \`stages\`, or \`stage\` calls to get targeted information instead of trying to read everything.
|
|
126
|
+
- Offer to help the user on another task instead of anxiously polling or help the user run another workflow if they need.
|
|
127
|
+
- Use run-control and messaging actions (\`send\`, \`pause\`, \`resume\`, \`interrupt\`, \`kill\`) only when needed to answer prompts, steer a stage, resume or interrupt paused work, or respond to user requests/control signals.
|
|
125
128
|
- For transcripts, avoid reading whole session transcripts at once. Use \`stages\` or \`stage\` to get \`sessionFile\`/\`transcriptPath\`, quote the exact path without rewriting separators (preserve Windows backslashes), search it with \`rg\`/\`grep\`, and read small relevant ranges; use \`transcript\` with explicit \`tail\` or \`limit\` only for quick recent-context checks.
|
|
126
|
-
- If a user asks to create or edit a workflow, use the create-spec skill when available and ask detailed clarifying questions until you understand its purpose, inputs, stages, handoffs, validation, and success criteria. Then read the workflow docs/examples and implement the workflow from the created spec directly as a TypeScript definition.
|
|
127
|
-
|
|
129
|
+
- If a user asks to create or edit a workflow, use the create-spec skill when available and ask detailed clarifying questions until you understand its purpose, inputs, stages, handoffs, validation, and success criteria. Then read the workflow docs/examples and implement the workflow from the created spec directly as a TypeScript definition. After you implement the workflow, reload it to access it and run it with test inputs to validate it works as intended before presenting it to the user.
|
|
130
|
+
- Tip: when designing workflows, implement it in a way that you pass information from stage to stage by writing it to a file or artifact (either deterministic or model-driven), pass the path with \`reads\`, and explicitly prompt the downstream agent with wording like \`Read the file at <path>...\`; do not inject large \`previous\` payloads or session history into the next prompt unless explicitly requested to.
|
|
131
|
+
- If you run \`ralph\` or \`goal\` workflow, define an objective that includes tight scope, concrete and verifiable done criteria, and validation steps; then monitor progress as above instead of doing parallel implementation yourself.`;
|
|
128
132
|
let prompt = `You are an expert coding assistant operating named Atomic, a coding agent harness. You help users by reading files, executing commands, editing code, and writing new files.
|
|
129
133
|
|
|
130
134
|
Available tools:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"system-prompt.js","sourceRoot":"","sources":["../../src/core/system-prompt.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,EAAE,qBAAqB,EAAc,MAAM,aAAa,CAAC;AAEhE,MAAM,oBAAoB,GAAG;IAC3B,MAAM;IACN,MAAM;IACN,MAAM;IACN,OAAO;IACP,mBAAmB;IACnB,MAAM;CACE,CAAC;AAoCX,kEAAkE;AAClE,MAAM,UAAU,iBAAiB,CAAC,OAAiC;IACjE,MAAM,EACJ,YAAY,EACZ,aAAa,EACb,aAAa,EAC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BACb,QAAQ;cACf,YAAY;yGAC+E,QAAQ,kCAAkC,YAAY;;;8GAGjD,CAAC;IAE7G,IAAI,aAAa,EAAE,CAAC;QAClB,MAAM,IAAI,aAAa,CAAC;IAC1B,CAAC;IAED,+BAA+B;IAC/B,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,2BAA2B,CAAC;QACtC,MAAM,IAAI,mDAAmD,CAAC;QAC9D,KAAK,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,YAAY,EAAE,CAAC;YACvD,MAAM,IAAI,wBAAwB,QAAQ,QAAQ,OAAO,uBAAuB,CAAC;QACnF,CAAC;IACH,CAAC;IAED,yDAAyD;IACzD,IAAI,OAAO,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACjC,MAAM,IAAI,qBAAqB,CAAC,MAAM,CAAC,CAAC;IAC1C,CAAC;IAED,uDAAuD;IACvD,MAAM,IAAI,+CAA+C,SAAS,EAAE,CAAC;IACrE,MAAM,IAAI,4BAA4B,mBAAmB,EAAE,CAAC;IAC5D,MAAM,IAAI,mBAAmB,IAAI,EAAE,CAAC;IACpC,MAAM,IAAI,gCAAgC,SAAS,EAAE,CAAC;IAEtD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["/**\n * System prompt construction and project context loading\n */\n\nimport { getDocsPath, getExamplesPath, getReadmePath } from \"../config.ts\";\nimport { formatSkillsForPrompt, type Skill } from \"./skills.ts\";\n\nconst DEFAULT_PROMPT_TOOLS = [\n \"read\",\n \"bash\",\n \"edit\",\n \"write\",\n \"ask_user_question\",\n \"todo\",\n] as const;\n\nexport interface SystemPromptModel {\n /** Provider identifier for the selected model. */\n provider: string;\n /** Stable provider-specific model identifier. */\n id: string;\n /** Human-readable model name, when available. */\n name?: string;\n}\n\nexport interface BuildSystemPromptOptions {\n /** Custom system prompt (replaces default). */\n customPrompt?: string;\n /** Tools to include in prompt. Default: [read, bash, edit, write, ask_user_question, todo] */\n selectedTools?: string[];\n /** Tool names explicitly excluded by the caller and omitted from generated guidance. */\n excludedTools?: string[];\n /** Optional one-line tool snippets keyed by tool name. */\n toolSnippets?: Record<string, string>;\n /** Additional guideline bullets appended to the default system prompt guidelines. */\n promptGuidelines?: string[];\n /** Text to append to system prompt. */\n appendSystemPrompt?: string;\n /** Working directory. */\n cwd: string;\n /** Currently selected model, used for model-aware prompt metadata. */\n selectedModel?: SystemPromptModel;\n /** Current reasoning/thinking level for the selected model. */\n selectedThinkingLevel?: string;\n /** Pre-loaded context files. */\n contextFiles?: Array<{ path: string; content: string }>;\n /** Pre-loaded skills. */\n skills?: Skill[];\n}\n\n/** Build the system prompt with tools, guidelines, and context */\nexport function buildSystemPrompt(options: BuildSystemPromptOptions): string {\n const {\n customPrompt,\n selectedTools,\n excludedTools,\n toolSnippets,\n promptGuidelines,\n appendSystemPrompt,\n cwd,\n selectedModel,\n selectedThinkingLevel,\n contextFiles: providedContextFiles,\n skills: providedSkills,\n } = options;\n const resolvedCwd = cwd;\n const promptCwd = resolvedCwd.replace(/\\\\/g, \"/\");\n\n const now = new Date();\n const year = now.getFullYear();\n const month = String(now.getMonth() + 1).padStart(2, \"0\");\n const day = String(now.getDate()).padStart(2, \"0\");\n const date = `${year}-${month}-${day}`;\n\n const appendSection = appendSystemPrompt ? `\\n\\n${appendSystemPrompt}` : \"\";\n const modelName =\n selectedModel?.name?.trim() || selectedModel?.id || \"unknown\";\n const modelReasoningLevel = selectedThinkingLevel?.trim() || \"off\";\n\n const contextFiles = providedContextFiles ?? [];\n const skills = providedSkills ?? [];\n const explicitlyExcludedTools = new Set(excludedTools ?? []);\n const isPromptToolAvailable = (name: string): boolean =>\n (!selectedTools || selectedTools.includes(name)) &&\n !explicitlyExcludedTools.has(name);\n\n if (customPrompt) {\n let prompt = customPrompt;\n\n if (appendSection) {\n prompt += appendSection;\n }\n\n // Append project context files\n if (contextFiles.length > 0) {\n prompt += \"\\n\\n# Project Context\\n\\n\";\n prompt += \"Project-specific instructions and guidelines:\\n\\n\";\n for (const { path: filePath, content } of contextFiles) {\n prompt += `<context_file path=\\\"${filePath}\\\">\\n${content}\\n</context_file>\\n\\n`;\n }\n }\n\n // Append skills section (only if read tool is available)\n if (isPromptToolAvailable(\"read\") && skills.length > 0) {\n prompt += formatSkillsForPrompt(skills);\n }\n\n // Add model metadata, date, and working directory last\n prompt += `\\nModel name (used for commit attribution): ${modelName}`;\n prompt += `\\nModel reasoning level: ${modelReasoningLevel}`;\n prompt += `\\nCurrent date: ${date}`;\n prompt += `\\nCurrent working directory: ${promptCwd}`;\n\n return prompt;\n }\n\n // Get absolute paths to documentation and examples\n const readmePath = getReadmePath();\n const docsPath = getDocsPath();\n const examplesPath = getExamplesPath();\n\n // Build tools list based on selected tools.\n // A tool appears in Available tools only when the caller provides a one-line snippet.\n const tools = (selectedTools ?? DEFAULT_PROMPT_TOOLS).filter(\n (name) => !explicitlyExcludedTools.has(name),\n );\n const visibleTools = tools.filter((name) => !!toolSnippets?.[name]);\n const toolsList =\n visibleTools.length > 0\n ? visibleTools\n .map((name) => `- ${name}: ${toolSnippets![name]}`)\n .join(\"\\n\")\n : \"(none)\";\n\n // Build guidelines based on which tools are actually available\n const guidelinesList: string[] = [];\n const guidelinesSet = new Set<string>();\n const addGuideline = (guideline: string): void => {\n if (guidelinesSet.has(guideline)) {\n return;\n }\n guidelinesSet.add(guideline);\n guidelinesList.push(guideline);\n };\n\n const hasBash = tools.includes(\"bash\");\n const hasGrep = tools.includes(\"grep\");\n const hasFind = tools.includes(\"find\");\n const hasLs = tools.includes(\"ls\");\n const hasRead = tools.includes(\"read\");\n\n // File exploration guidelines\n if (hasBash && !hasGrep && !hasFind && !hasLs) {\n addGuideline(\"Use bash for file operations like ls, rg, find\");\n } else if (hasBash && (hasGrep || hasFind || hasLs)) {\n addGuideline(\n \"Prefer grep/find/ls tools over bash for file exploration (faster, respects .gitignore)\",\n );\n }\n\n for (const guideline of promptGuidelines ?? []) {\n const normalized = guideline.trim();\n if (normalized.length > 0) {\n addGuideline(normalized);\n }\n }\n\n // Always include these\n addGuideline(\"Be concise in your responses\");\n addGuideline(\"Show file paths clearly when working with files\");\n\n const guidelines = guidelinesList.map((g) => `- ${g}`).join(\"\\n\");\n\n const askUserQuestionGuidance = explicitlyExcludedTools.has(\n \"ask_user_question\",\n )\n ? \"\"\n : \"- Always ask clarifying questions if the user's request is ambiguous or lacks necessary details. NEVER make assumptions about what the user wants. If you find yourself circling in thought and asking what the user \\\"really\\\" wants, stop and ask the user for clarification using the ask_user_question tool if available. It's better to clarify intent rather than to guess.\\n- **Asking the user is a strict requirement**: Whenever you need to ask the user anything — a clarification, a decision, a choice between options, a confirmation, or any yes/no question — you MUST ask it by calling the `ask_user_question` tool. Never pose a question to the user as plain assistant text. Every question you direct to the user goes through `ask_user_question`; writing the question in prose instead of calling the tool is not allowed.\";\n const todoGuidance = explicitlyExcludedTools.has(\"todo\")\n ? \"\"\n : \"- **To-do management**: If the user has a complex task that can be broken down into actionable steps, use the `todo` tool to create a task list before proceeding. This ensures clarity and alignment with the user's goals and that you have a way to track your work and ensure you are meeting the user's expectations.\";\n\n const subagentGuidance = explicitlyExcludedTools.has(\"subagent\")\n ? \"\"\n : `- **Subagent Orchestration**:\n - To avoid draining your context window, prefer to use subagents for complex tasks all non-trivial operations should be delegated to subagents.\n - You should delegate running bash commands (particularly ones that are likely to produce lots of output) such as investigating with the \\`aws\\` CLI, using the \\`gh\\` CLI, digging through logs to \\`bash\\` subagents.\n - You should use separate subagents for separate tasks, and you may launch them in parallel, but do not delegate multiple tasks that are likely to have significant overlap to separate subagents.\n - Sometimes subagents will take a long time. DO NOT attempt to do the job yourself while waiting for the subagent to respond Instead, use the time to plan out your next steps.\n - **Debugging**: When a user asks about debugging, spawn a debugger subagent first.\n - Do not attempt to debug or analyze code yourself without first consulting the debugger subagent.\n - Explain the debugger's insights to the user clearly and concisely.\n - Once the user confirms, implement the necessary code changes based on those insights.\n - If the user has follow-up questions, spawn additional debugger and research subagents as needed.`;\n\n const workflowGuidance = explicitlyExcludedTools.has(\"workflow\")\n ? \"\"\n : `- **Workflows**: Use the \\`workflow\\` tool for existing named workflows and for repeatable, inspectable, resumable, or multi-stage processes; use direct \\`task\\`, \\`tasks\\`, or \\`chain\\` workflow calls for one-off tracked work when that is useful.\n - For unfamiliar named workflows, discover with \\`action: \"list\"\\`, inspect with \\`action: \"get\"\\` or \\`action: \"inputs\"\\`, and run with \\`action: \"run\"\\`, \\`workflow\\`, and validated \\`inputs\\`; do not invent workflow names or input keys.\n - Monitor long-running workflow runs through lifecycle notices and targeted \\`status\\`/\\`stages\\`/\\`stage\\` checks when you need new information; do not micro-manage every stage or create sleep/status polling loops.\n - Use run-control and messaging actions (\\`send\\`, \\`pause\\`, \\`resume\\`, \\`interrupt\\`, \\`kill\\`) only when needed to answer prompts, steer a stage, resume or interrupt paused work, or respond to user requests/control signals.\n - For transcripts, avoid reading whole session transcripts at once. Use \\`stages\\` or \\`stage\\` to get \\`sessionFile\\`/\\`transcriptPath\\`, quote the exact path without rewriting separators (preserve Windows backslashes), search it with \\`rg\\`/\\`grep\\`, and read small relevant ranges; use \\`transcript\\` with explicit \\`tail\\` or \\`limit\\` only for quick recent-context checks.\n - If a user asks to create or edit a workflow, use the create-spec skill when available and ask detailed clarifying questions until you understand its purpose, inputs, stages, handoffs, validation, and success criteria. Then read the workflow docs/examples and implement the workflow from the created spec directly as a TypeScript definition.\n - If you run \\`ralph\\` or \\`goal\\`, define an objective that includes tight scope, concrete and verifiable done criteria, and validation steps; then monitor progress as above instead of doing parallel implementation yourself.`;\n\n let prompt = `You are an expert coding assistant operating named Atomic, a coding agent harness. You help users by reading files, executing commands, editing code, and writing new files.\n\nAvailable tools:\n${toolsList}\n\nIn addition to the tools above, you may have access to other custom tools depending on the project.\n\nGuidelines:\n${guidelines}\n${askUserQuestionGuidance}\n${todoGuidance}\n${subagentGuidance}\n${workflowGuidance}\n\nAtomic documentation (read only when the user asks about customizing Atomic itself, its SDK, creating workflows, packages, extensions, themes, skills, or TUI):\n- Main documentation: ${readmePath}\n- Additional docs: ${docsPath}\n- Examples: ${examplesPath} (extensions, custom tools, SDK)\n- Docs/examples references above must be resolved against these absolute roots; e.g. docs/foo.md means ${docsPath}/foo.md and examples/bar means ${examplesPath}/bar.\n- When asked about: atomic workflows (docs/workflows.md), extensions (docs/extensions.md, examples/extensions/), themes (docs/themes.md), skills (docs/skills.md), prompt templates (docs/prompt-templates.md), TUI components (docs/tui.md), keybindings (docs/keybindings.md), SDK integrations (docs/sdk.md), custom providers (docs/custom-provider.md), adding models (docs/models.md), atomic packages (docs/packages.md)\n- When working on Atomic topics, read the docs and examples, and follow .md cross-references before implementing\n- Always read Atomic .md files completely and follow links to related docs (e.g., tui.md for TUI API details)`;\n\n if (appendSection) {\n prompt += appendSection;\n }\n\n // Append project context files\n if (contextFiles.length > 0) {\n prompt += \"\\n\\n# Project Context\\n\\n\";\n prompt += \"Project-specific instructions and guidelines:\\n\\n\";\n for (const { path: filePath, content } of contextFiles) {\n prompt += `<context_file path=\\\"${filePath}\\\">\\n${content}\\n</context_file>\\n\\n`;\n }\n }\n\n // Append skills section (only if read tool is available)\n if (hasRead && skills.length > 0) {\n prompt += formatSkillsForPrompt(skills);\n }\n\n // Add model metadata, date, and working directory last\n prompt += `\\nModel name (used for commit attribution): ${modelName}`;\n prompt += `\\nModel reasoning level: ${modelReasoningLevel}`;\n prompt += `\\nCurrent date: ${date}`;\n prompt += `\\nCurrent working directory: ${promptCwd}`;\n\n return prompt;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"system-prompt.js","sourceRoot":"","sources":["../../src/core/system-prompt.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,EAAE,qBAAqB,EAAc,MAAM,aAAa,CAAC;AAEhE,MAAM,oBAAoB,GAAG;IAC3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AC,CAAC,EAAE;QACJ,CAAC,CAAC;;;;;;;;;;6OAUuO,CAAC;IAE5O,IAAI,MAAM,GAAG;;;EAGb,SAAS;;;;;EAKT,UAAU;EACV,uBAAuB;EACvB,YAAY;EACZ,gBAAgB;EAChB,gBAAgB;;;wBAGM,UAAU;qBACb,QAAQ;cACf,YAAY;yGAC+E,QAAQ,kCAAkC,YAAY;;;8GAGjD,CAAC;IAE7G,IAAI,aAAa,EAAE,CAAC;QAClB,MAAM,IAAI,aAAa,CAAC;IAC1B,CAAC;IAED,+BAA+B;IAC/B,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,2BAA2B,CAAC;QACtC,MAAM,IAAI,mDAAmD,CAAC;QAC9D,KAAK,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,YAAY,EAAE,CAAC;YACvD,MAAM,IAAI,wBAAwB,QAAQ,QAAQ,OAAO,uBAAuB,CAAC;QACnF,CAAC;IACH,CAAC;IAED,yDAAyD;IACzD,IAAI,OAAO,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACjC,MAAM,IAAI,qBAAqB,CAAC,MAAM,CAAC,CAAC;IAC1C,CAAC;IAED,uDAAuD;IACvD,MAAM,IAAI,+CAA+C,SAAS,EAAE,CAAC;IACrE,MAAM,IAAI,4BAA4B,mBAAmB,EAAE,CAAC;IAC5D,MAAM,IAAI,mBAAmB,IAAI,EAAE,CAAC;IACpC,MAAM,IAAI,gCAAgC,SAAS,EAAE,CAAC;IAEtD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["/**\n * System prompt construction and project context loading\n */\n\nimport { getDocsPath, getExamplesPath, getReadmePath } from \"../config.ts\";\nimport { formatSkillsForPrompt, type Skill } from \"./skills.ts\";\n\nconst DEFAULT_PROMPT_TOOLS = [\n \"read\",\n \"bash\",\n \"edit\",\n \"write\",\n \"ask_user_question\",\n \"todo\",\n] as const;\n\nexport interface SystemPromptModel {\n /** Provider identifier for the selected model. */\n provider: string;\n /** Stable provider-specific model identifier. */\n id: string;\n /** Human-readable model name, when available. */\n name?: string;\n}\n\nexport interface BuildSystemPromptOptions {\n /** Custom system prompt (replaces default). */\n customPrompt?: string;\n /** Tools to include in prompt. Default: [read, bash, edit, write, ask_user_question, todo] */\n selectedTools?: string[];\n /** Tool names explicitly excluded by the caller and omitted from generated guidance. */\n excludedTools?: string[];\n /** Optional one-line tool snippets keyed by tool name. */\n toolSnippets?: Record<string, string>;\n /** Additional guideline bullets appended to the default system prompt guidelines. */\n promptGuidelines?: string[];\n /** Text to append to system prompt. */\n appendSystemPrompt?: string;\n /** Working directory. */\n cwd: string;\n /** Currently selected model, used for model-aware prompt metadata. */\n selectedModel?: SystemPromptModel;\n /** Current reasoning/thinking level for the selected model. */\n selectedThinkingLevel?: string;\n /** Pre-loaded context files. */\n contextFiles?: Array<{ path: string; content: string }>;\n /** Pre-loaded skills. */\n skills?: Skill[];\n}\n\n/** Build the system prompt with tools, guidelines, and context */\nexport function buildSystemPrompt(options: BuildSystemPromptOptions): string {\n const {\n customPrompt,\n selectedTools,\n excludedTools,\n toolSnippets,\n promptGuidelines,\n appendSystemPrompt,\n cwd,\n selectedModel,\n selectedThinkingLevel,\n contextFiles: providedContextFiles,\n skills: providedSkills,\n } = options;\n const resolvedCwd = cwd;\n const promptCwd = resolvedCwd.replace(/\\\\/g, \"/\");\n\n const now = new Date();\n const year = now.getFullYear();\n const month = String(now.getMonth() + 1).padStart(2, \"0\");\n const day = String(now.getDate()).padStart(2, \"0\");\n const date = `${year}-${month}-${day}`;\n\n const appendSection = appendSystemPrompt ? `\\n\\n${appendSystemPrompt}` : \"\";\n const modelName =\n selectedModel?.name?.trim() || selectedModel?.id || \"unknown\";\n const modelReasoningLevel = selectedThinkingLevel?.trim() || \"off\";\n\n const contextFiles = providedContextFiles ?? [];\n const skills = providedSkills ?? [];\n const explicitlyExcludedTools = new Set(excludedTools ?? []);\n const isPromptToolAvailable = (name: string): boolean =>\n (!selectedTools || selectedTools.includes(name)) &&\n !explicitlyExcludedTools.has(name);\n\n if (customPrompt) {\n let prompt = customPrompt;\n\n if (appendSection) {\n prompt += appendSection;\n }\n\n // Append project context files\n if (contextFiles.length > 0) {\n prompt += \"\\n\\n# Project Context\\n\\n\";\n prompt += \"Project-specific instructions and guidelines:\\n\\n\";\n for (const { path: filePath, content } of contextFiles) {\n prompt += `<context_file path=\\\"${filePath}\\\">\\n${content}\\n</context_file>\\n\\n`;\n }\n }\n\n // Append skills section (only if read tool is available)\n if (isPromptToolAvailable(\"read\") && skills.length > 0) {\n prompt += formatSkillsForPrompt(skills);\n }\n\n // Add model metadata, date, and working directory last\n prompt += `\\nModel name (used for commit attribution): ${modelName}`;\n prompt += `\\nModel reasoning level: ${modelReasoningLevel}`;\n prompt += `\\nCurrent date: ${date}`;\n prompt += `\\nCurrent working directory: ${promptCwd}`;\n\n return prompt;\n }\n\n // Get absolute paths to documentation and examples\n const readmePath = getReadmePath();\n const docsPath = getDocsPath();\n const examplesPath = getExamplesPath();\n\n // Build tools list based on selected tools.\n // A tool appears in Available tools only when the caller provides a one-line snippet.\n const tools = (selectedTools ?? DEFAULT_PROMPT_TOOLS).filter(\n (name) => !explicitlyExcludedTools.has(name),\n );\n const visibleTools = tools.filter((name) => !!toolSnippets?.[name]);\n const toolsList =\n visibleTools.length > 0\n ? visibleTools\n .map((name) => `- ${name}: ${toolSnippets![name]}`)\n .join(\"\\n\")\n : \"(none)\";\n\n // Build guidelines based on which tools are actually available\n const guidelinesList: string[] = [];\n const guidelinesSet = new Set<string>();\n const addGuideline = (guideline: string): void => {\n if (guidelinesSet.has(guideline)) {\n return;\n }\n guidelinesSet.add(guideline);\n guidelinesList.push(guideline);\n };\n\n const hasBash = tools.includes(\"bash\");\n const hasGrep = tools.includes(\"grep\");\n const hasFind = tools.includes(\"find\");\n const hasLs = tools.includes(\"ls\");\n const hasRead = tools.includes(\"read\");\n\n // File exploration guidelines\n if (hasBash && !hasGrep && !hasFind && !hasLs) {\n addGuideline(\"Use bash for file operations like ls, rg, find\");\n } else if (hasBash && (hasGrep || hasFind || hasLs)) {\n addGuideline(\n \"Prefer grep/find/ls tools over bash for file exploration (faster, respects .gitignore)\",\n );\n }\n\n for (const guideline of promptGuidelines ?? []) {\n const normalized = guideline.trim();\n if (normalized.length > 0) {\n addGuideline(normalized);\n }\n }\n\n // Always include these\n addGuideline(\"Be concise in your responses\");\n addGuideline(\"Show file paths clearly when working with files\");\n\n const guidelines = guidelinesList.map((g) => `- ${g}`).join(\"\\n\");\n\n const askUserQuestionGuidance = explicitlyExcludedTools.has(\n \"ask_user_question\",\n )\n ? \"\"\n : \"- Always ask clarifying questions if the user's request is ambiguous or lacks necessary details. NEVER make assumptions about what the user wants. If you find yourself circling in thought and asking what the user \\\"really\\\" wants, stop and ask the user for clarification using the ask_user_question tool if available. It's better to clarify intent rather than to guess.\\n- **Asking the user is a strict requirement**: Whenever you need to ask the user anything — a clarification, a decision, a choice between options, a confirmation, or any yes/no question — you MUST ask it by calling the `ask_user_question` tool. Never pose a question to the user as plain assistant text. Every question you direct to the user goes through `ask_user_question`; writing the question in prose instead of calling the tool is not allowed.\";\n const todoGuidance = explicitlyExcludedTools.has(\"todo\")\n ? \"\"\n : \"- **To-do management**: If the user has a complex task that can be broken down into actionable steps, use the `todo` tool to create a task list before proceeding. This ensures clarity and alignment with the user's goals and that you have a way to track your work and ensure you are meeting the user's expectations.\";\n\n const subagentGuidance = explicitlyExcludedTools.has(\"subagent\")\n ? \"\"\n : `- **Subagent Orchestration**:\n - To avoid draining your context window, prefer to use subagents for complex tasks all non-trivial operations should be delegated to subagents.\n - You should delegate running bash commands (particularly ones that are likely to produce lots of output) such as investigating with the \\`aws\\` CLI, using the \\`gh\\` CLI, digging through logs to \\`bash\\` subagents.\n - You should use separate subagents for separate tasks, and you may launch them in parallel, but do not delegate multiple tasks that are likely to have significant overlap to separate subagents.\n - Sometimes subagents will take a long time. DO NOT attempt to do the job yourself while waiting for the subagent to respond Instead, use the time to plan out your next steps.\n - **Debugging**: When a user asks about debugging, spawn a debugger subagent first.\n - Do not attempt to debug or analyze code yourself without first consulting the debugger subagent.\n - Explain the debugger's insights to the user clearly and concisely.\n - Once the user confirms, implement the necessary code changes based on those insights.\n - If the user has follow-up questions, spawn additional debugger and research subagents as needed.`;\n\n const workflowGuidance = explicitlyExcludedTools.has(\"workflow\")\n ? \"\"\n : `- **Workflows**: Use the \\`workflow\\` tool for existing named workflows and for repeatable, inspectable, resumable, or multi-stage processes; use direct \\`task\\`, \\`tasks\\`, or \\`chain\\` workflow calls for one-off tracked work when that is useful.\n - For unfamiliar named workflows, discover with \\`action: \"list\"\\`, inspect with \\`action: \"get\"\\` or \\`action: \"inputs\"\\`, and run with \\`action: \"run\"\\`, \\`workflow\\`, and validated \\`inputs\\`; do not invent workflow names or input keys.\n - Once you run a workflow with the workflow tool, end your current turn and wait for the next user input or lifecycle notice.\n - You will automatically be alerted of key lifecycle events like start, finish, failure; do not attempt to track its progress yourself or read its logs or stages unless the user asks you to or you need to check in on it to get information for the next step.\n - If the user needs information from the workflow run, use \\`status\\`, \\`stages\\`, or \\`stage\\` calls to get targeted information instead of trying to read everything.\n - Offer to help the user on another task instead of anxiously polling or help the user run another workflow if they need.\n - Use run-control and messaging actions (\\`send\\`, \\`pause\\`, \\`resume\\`, \\`interrupt\\`, \\`kill\\`) only when needed to answer prompts, steer a stage, resume or interrupt paused work, or respond to user requests/control signals.\n - For transcripts, avoid reading whole session transcripts at once. Use \\`stages\\` or \\`stage\\` to get \\`sessionFile\\`/\\`transcriptPath\\`, quote the exact path without rewriting separators (preserve Windows backslashes), search it with \\`rg\\`/\\`grep\\`, and read small relevant ranges; use \\`transcript\\` with explicit \\`tail\\` or \\`limit\\` only for quick recent-context checks.\n - If a user asks to create or edit a workflow, use the create-spec skill when available and ask detailed clarifying questions until you understand its purpose, inputs, stages, handoffs, validation, and success criteria. Then read the workflow docs/examples and implement the workflow from the created spec directly as a TypeScript definition. After you implement the workflow, reload it to access it and run it with test inputs to validate it works as intended before presenting it to the user.\n - Tip: when designing workflows, implement it in a way that you pass information from stage to stage by writing it to a file or artifact (either deterministic or model-driven), pass the path with \\`reads\\`, and explicitly prompt the downstream agent with wording like \\`Read the file at <path>...\\`; do not inject large \\`previous\\` payloads or session history into the next prompt unless explicitly requested to.\n - If you run \\`ralph\\` or \\`goal\\` workflow, define an objective that includes tight scope, concrete and verifiable done criteria, and validation steps; then monitor progress as above instead of doing parallel implementation yourself.`;\n\n let prompt = `You are an expert coding assistant operating named Atomic, a coding agent harness. You help users by reading files, executing commands, editing code, and writing new files.\n\nAvailable tools:\n${toolsList}\n\nIn addition to the tools above, you may have access to other custom tools depending on the project.\n\nGuidelines:\n${guidelines}\n${askUserQuestionGuidance}\n${todoGuidance}\n${subagentGuidance}\n${workflowGuidance}\n\nAtomic documentation (read only when the user asks about customizing Atomic itself, its SDK, creating workflows, packages, extensions, themes, skills, or TUI):\n- Main documentation: ${readmePath}\n- Additional docs: ${docsPath}\n- Examples: ${examplesPath} (extensions, custom tools, SDK)\n- Docs/examples references above must be resolved against these absolute roots; e.g. docs/foo.md means ${docsPath}/foo.md and examples/bar means ${examplesPath}/bar.\n- When asked about: atomic workflows (docs/workflows.md), extensions (docs/extensions.md, examples/extensions/), themes (docs/themes.md), skills (docs/skills.md), prompt templates (docs/prompt-templates.md), TUI components (docs/tui.md), keybindings (docs/keybindings.md), SDK integrations (docs/sdk.md), custom providers (docs/custom-provider.md), adding models (docs/models.md), atomic packages (docs/packages.md)\n- When working on Atomic topics, read the docs and examples, and follow .md cross-references before implementing\n- Always read Atomic .md files completely and follow links to related docs (e.g., tui.md for TUI API details)`;\n\n if (appendSection) {\n prompt += appendSection;\n }\n\n // Append project context files\n if (contextFiles.length > 0) {\n prompt += \"\\n\\n# Project Context\\n\\n\";\n prompt += \"Project-specific instructions and guidelines:\\n\\n\";\n for (const { path: filePath, content } of contextFiles) {\n prompt += `<context_file path=\\\"${filePath}\\\">\\n${content}\\n</context_file>\\n\\n`;\n }\n }\n\n // Append skills section (only if read tool is available)\n if (hasRead && skills.length > 0) {\n prompt += formatSkillsForPrompt(skills);\n }\n\n // Add model metadata, date, and working directory last\n prompt += `\\nModel name (used for commit attribution): ${modelName}`;\n prompt += `\\nModel reasoning level: ${modelReasoningLevel}`;\n prompt += `\\nCurrent date: ${date}`;\n prompt += `\\nCurrent working directory: ${promptCwd}`;\n\n return prompt;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ask-user-question.d.ts","sourceRoot":"","sources":["../../../../src/core/tools/ask-user-question/ask-user-question.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAIhE,OAAO,EAAE,0BAA0B,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC1F,OAAO,EAIN,KAAK,YAAY,EAGjB,oBAAoB,EACpB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAI/E,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,YAAY,GAAG,kBAAkB,EAAE,CAWlF;AAED,eAAO,MAAM,sBAAsB,iGAA0I,CAAC;AAC9K,eAAO,MAAM,yBAAyB,EAAE,MAAM,EAK7C,CAAC;AAEF,wBAAgB,mCAAmC,IAAI,cAAc,CAAC,OAAO,oBAAoB,EAAE,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"ask-user-question.d.ts","sourceRoot":"","sources":["../../../../src/core/tools/ask-user-question/ask-user-question.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAIhE,OAAO,EAAE,0BAA0B,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC1F,OAAO,EAIN,KAAK,YAAY,EAGjB,oBAAoB,EACpB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAI/E,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,YAAY,GAAG,kBAAkB,EAAE,CAWlF;AAED,eAAO,MAAM,sBAAsB,iGAA0I,CAAC;AAC9K,eAAO,MAAM,yBAAyB,EAAE,MAAM,EAK7C,CAAC;AAEF,wBAAgB,mCAAmC,IAAI,cAAc,CAAC,OAAO,oBAAoB,EAAE,OAAO,CAAC,CA4E1G;AAED,OAAO,EAAE,0BAA0B,EAAE,eAAe,EAAE,CAAC","sourcesContent":["import type { ToolDefinition } from \"../../extensions/types.ts\";\nimport { loadConfig, validateGuidanceFields } from \"./config.ts\";\nimport { QuestionnaireSession } from \"./state/questionnaire-session.ts\";\nimport { ROW_INTENT_META, sentinelsToAppend } from \"./state/row-intent.ts\";\nimport { buildQuestionnaireResponse, buildToolResult } from \"./tool/response-envelope.ts\";\nimport {\n\tMAX_OPTIONS,\n\tMAX_QUESTIONS,\n\tMIN_OPTIONS,\n\ttype QuestionData,\n\ttype QuestionnaireResult,\n\ttype QuestionParams,\n\tQuestionParamsSchema,\n} from \"./tool/types.ts\";\nimport { validateQuestionnaire } from \"./tool/validate-questionnaire.ts\";\nimport type { WrappingSelectItem } from \"./view/components/wrapping-select.ts\";\n\nconst ERROR_NO_UI = \"Error: UI not available (running in non-interactive mode)\";\n\nexport function buildItemsForQuestion(question: QuestionData): WrappingSelectItem[] {\n\tconst items: WrappingSelectItem[] = question.options.map((o) => ({\n\t\tkind: \"option\",\n\t\tlabel: o.label,\n\t\tdescription: o.description,\n\t}));\n\tconst hasAnyPreview = question.options.some((o) => typeof o.preview === \"string\" && o.preview.length > 0);\n\tfor (const kind of sentinelsToAppend(question, hasAnyPreview)) {\n\t\titems.push({ kind, label: ROW_INTENT_META[kind].label });\n\t}\n\treturn items;\n}\n\nexport const DEFAULT_PROMPT_SNIPPET = `Ask the user up to ${MAX_QUESTIONS} structured questions (${MIN_OPTIONS}-${MAX_OPTIONS} options each) when requirements are ambiguous`;\nexport const DEFAULT_PROMPT_GUIDELINES: string[] = [\n\t`Use ask_user_question whenever the user's request is underspecified and you cannot proceed without concrete decisions — you can ask up to ${MAX_QUESTIONS} questions per invocation.`,\n\t`Each question MUST have ${MIN_OPTIONS}-${MAX_OPTIONS} options. Every option requires a concise label (1-5 words) and a description explaining what the choice means or its trade-offs. The user can additionally type a custom answer (\"Type something.\" row is appended automatically to single-select questions) or pick \"Chat about this\" to abandon the questionnaire.`,\n\t`Set multiSelect: true when multiple answers are valid; this suppresses the \"Type something.\" row. Provide an options[].preview markdown string when an option benefits from richer side-by-side context (mockups, code snippets, diagrams, configs) — single-select only. NOTE: any non-empty preview on a single-select question ALSO suppresses the \"Type something.\" row (no room in the side-by-side layout); \"Chat about this\" remains the escape hatch. If you recommend a specific option, make it the first option and append \"(Recommended)\" to its label.`,\n\t\"Do not stack multiple ask_user_question calls back-to-back — group all clarifying questions into one invocation.\",\n];\n\nexport function createAskUserQuestionToolDefinition(): ToolDefinition<typeof QuestionParamsSchema, unknown> {\n\tconst guidance = validateGuidanceFields(loadConfig().guidance);\n\treturn {\n\t\tname: \"ask_user_question\",\n\t\tlabel: \"Ask User Question\",\n\t\tdescription: `Ask the user one or more structured questions during execution. Use when you need to:\n1. Gather user preferences or requirements\n2. Clarify ambiguous instructions\n3. Get decisions on implementation choices as you work\n4. Offer choices to the user about what direction to take\n\nUsage notes:\n- Users will always be able to type a custom answer (\"Type something.\" row is appended automatically to every single-select question) or pick \"Chat about this\" to abandon the questionnaire and continue in free-form conversation. Do NOT author \"Other\" / \"Type something.\" / \"Chat about this\" labels yourself — duplicates are rejected at runtime.\n- Use multiSelect: true to allow multiple answers to be selected for a question. The \"Type something.\" row is suppressed on multi-select questions, and is ALSO suppressed on single-select questions where any option carries a \\`preview\\` (the side-by-side layout has no room for inline custom text — \"Chat about this\" remains as the free-form escape hatch).\n- If you recommend a specific option, make that the first option in the list and add \"(Recommended)\" at the end of the label.\n\nPreview feature:\nUse the optional \\`preview\\` field on options when presenting concrete artifacts that users need to visually compare:\n- ASCII mockups of UI layouts or components\n- Code snippets showing different implementations\n- Diagram variations\n- Configuration examples\n\nPreview content is rendered as markdown in a monospace box. Multi-line text with newlines is supported. When any option has a preview, the UI switches to a side-by-side layout with a vertical option list on the left and preview on the right. Do not use previews for simple preference questions where labels and descriptions suffice. Note: previews are only supported for single-select questions (not multiSelect).`,\n\t\tpromptSnippet: guidance.promptSnippet ?? DEFAULT_PROMPT_SNIPPET,\n\t\tpromptGuidelines: guidance.promptGuidelines ?? DEFAULT_PROMPT_GUIDELINES,\n\t\tparameters: QuestionParamsSchema,\n\n\t\tasync execute(_toolCallId, params, signal, _onUpdate, ctx) {\n\t\t\tconst typed = params as unknown as QuestionParams;\n\t\t\tif (!ctx.hasUI) return buildToolResult(ERROR_NO_UI, { answers: [], cancelled: true, error: \"no_ui\" });\n\n\t\t\tconst validation = validateQuestionnaire(typed);\n\t\t\tif (!validation.ok) {\n\t\t\t\treturn buildToolResult(validation.message, {\n\t\t\t\t\tanswers: [],\n\t\t\t\t\tcancelled: true,\n\t\t\t\t\terror: validation.error,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst itemsByTab: WrappingSelectItem[][] = typed.questions.map((q) => buildItemsForQuestion(q));\n\n\t\t\t// Suspend the animated working loader for the lifetime of the blocking dialog.\n\t\t\t//\n\t\t\t// The questionnaire mounts inline, directly below the status/working-loader row.\n\t\t\t// That loader ticks every ~80ms and calls `requestRender()` on each frame. On a\n\t\t\t// short terminal the (tall) side-by-side dialog pushes the loader line above the\n\t\t\t// viewport top, so pi-tui's differential renderer sees `firstChanged < viewportTop`\n\t\t\t// and falls back to a full clear+replay (`\\x1b[2J\\x1b[H\\x1b[3J`) on every tick. The\n\t\t\t// transcript is replayed before the dialog each time, which is the flicker. The\n\t\t\t// loader conveys nothing while we're blocked on human input, so hide it for the\n\t\t\t// duration and restore it once the dialog closes (on every path).\n\t\t\t//\n\t\t\t// Guarded: some hosts (e.g. the workflow stage-UI broker) pass a minimal UI\n\t\t\t// context that only implements `custom`, so treat a missing loader control as a\n\t\t\t// no-op rather than throwing.\n\t\t\tctx.ui.setWorkingVisible?.(false);\n\t\t\ttry {\n\t\t\t\tconst result = await ctx.ui.custom<QuestionnaireResult>((tui, theme, _kb, done) => {\n\t\t\t\t\tconst session = new QuestionnaireSession({\n\t\t\t\t\t\ttui,\n\t\t\t\t\t\ttheme,\n\t\t\t\t\t\tparams: typed,\n\t\t\t\t\t\titemsByTab,\n\t\t\t\t\t\tdone,\n\t\t\t\t\t});\n\t\t\t\t\treturn session.component;\n\t\t\t\t}, { signal });\n\n\t\t\t\treturn buildQuestionnaireResponse(result, typed);\n\t\t\t} finally {\n\t\t\t\tctx.ui.setWorkingVisible?.(true);\n\t\t\t}\n\t\t},\n\t};\n}\n\nexport { buildQuestionnaireResponse, buildToolResult };\n"]}
|
|
@@ -64,17 +64,37 @@ Preview content is rendered as markdown in a monospace box. Multi-line text with
|
|
|
64
64
|
});
|
|
65
65
|
}
|
|
66
66
|
const itemsByTab = typed.questions.map((q) => buildItemsForQuestion(q));
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
67
|
+
// Suspend the animated working loader for the lifetime of the blocking dialog.
|
|
68
|
+
//
|
|
69
|
+
// The questionnaire mounts inline, directly below the status/working-loader row.
|
|
70
|
+
// That loader ticks every ~80ms and calls `requestRender()` on each frame. On a
|
|
71
|
+
// short terminal the (tall) side-by-side dialog pushes the loader line above the
|
|
72
|
+
// viewport top, so pi-tui's differential renderer sees `firstChanged < viewportTop`
|
|
73
|
+
// and falls back to a full clear+replay (`\x1b[2J\x1b[H\x1b[3J`) on every tick. The
|
|
74
|
+
// transcript is replayed before the dialog each time, which is the flicker. The
|
|
75
|
+
// loader conveys nothing while we're blocked on human input, so hide it for the
|
|
76
|
+
// duration and restore it once the dialog closes (on every path).
|
|
77
|
+
//
|
|
78
|
+
// Guarded: some hosts (e.g. the workflow stage-UI broker) pass a minimal UI
|
|
79
|
+
// context that only implements `custom`, so treat a missing loader control as a
|
|
80
|
+
// no-op rather than throwing.
|
|
81
|
+
ctx.ui.setWorkingVisible?.(false);
|
|
82
|
+
try {
|
|
83
|
+
const result = await ctx.ui.custom((tui, theme, _kb, done) => {
|
|
84
|
+
const session = new QuestionnaireSession({
|
|
85
|
+
tui,
|
|
86
|
+
theme,
|
|
87
|
+
params: typed,
|
|
88
|
+
itemsByTab,
|
|
89
|
+
done,
|
|
90
|
+
});
|
|
91
|
+
return session.component;
|
|
92
|
+
}, { signal });
|
|
93
|
+
return buildQuestionnaireResponse(result, typed);
|
|
94
|
+
}
|
|
95
|
+
finally {
|
|
96
|
+
ctx.ui.setWorkingVisible?.(true);
|
|
97
|
+
}
|
|
78
98
|
},
|
|
79
99
|
};
|
|
80
100
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ask-user-question.js","sourceRoot":"","sources":["../../../../src/core/tools/ask-user-question/ask-user-question.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC3E,OAAO,EAAE,0BAA0B,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC1F,OAAO,EACN,WAAW,EACX,aAAa,EACb,WAAW,EAIX,oBAAoB,GACpB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAGzE,MAAM,WAAW,GAAG,2DAA2D,CAAC;AAEhF,MAAM,UAAU,qBAAqB,CAAC,QAAsB;IAC3D,MAAM,KAAK,GAAyB,QAAQ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ateGuidanceFields } from \"./config.ts\";\nimport { QuestionnaireSession } from \"./state/questionnaire-session.ts\";\nimport { ROW_INTENT_META, sentinelsToAppend } from \"./state/row-intent.ts\";\nimport { buildQuestionnaireResponse, buildToolResult } from \"./tool/response-envelope.ts\";\nimport {\n\tMAX_OPTIONS,\n\tMAX_QUESTIONS,\n\tMIN_OPTIONS,\n\ttype QuestionData,\n\ttype QuestionnaireResult,\n\ttype QuestionParams,\n\tQuestionParamsSchema,\n} from \"./tool/types.ts\";\nimport { validateQuestionnaire } from \"./tool/validate-questionnaire.ts\";\nimport type { WrappingSelectItem } from \"./view/components/wrapping-select.ts\";\n\nconst ERROR_NO_UI = \"Error: UI not available (running in non-interactive mode)\";\n\nexport function buildItemsForQuestion(question: QuestionData): WrappingSelectItem[] {\n\tconst items: WrappingSelectItem[] = question.options.map((o) => ({\n\t\tkind: \"option\",\n\t\tlabel: o.label,\n\t\tdescription: o.description,\n\t}));\n\tconst hasAnyPreview = question.options.some((o) => typeof o.preview === \"string\" && o.preview.length > 0);\n\tfor (const kind of sentinelsToAppend(question, hasAnyPreview)) {\n\t\titems.push({ kind, label: ROW_INTENT_META[kind].label });\n\t}\n\treturn items;\n}\n\nexport const DEFAULT_PROMPT_SNIPPET = `Ask the user up to ${MAX_QUESTIONS} structured questions (${MIN_OPTIONS}-${MAX_OPTIONS} options each) when requirements are ambiguous`;\nexport const DEFAULT_PROMPT_GUIDELINES: string[] = [\n\t`Use ask_user_question whenever the user's request is underspecified and you cannot proceed without concrete decisions — you can ask up to ${MAX_QUESTIONS} questions per invocation.`,\n\t`Each question MUST have ${MIN_OPTIONS}-${MAX_OPTIONS} options. Every option requires a concise label (1-5 words) and a description explaining what the choice means or its trade-offs. The user can additionally type a custom answer (\"Type something.\" row is appended automatically to single-select questions) or pick \"Chat about this\" to abandon the questionnaire.`,\n\t`Set multiSelect: true when multiple answers are valid; this suppresses the \"Type something.\" row. Provide an options[].preview markdown string when an option benefits from richer side-by-side context (mockups, code snippets, diagrams, configs) — single-select only. NOTE: any non-empty preview on a single-select question ALSO suppresses the \"Type something.\" row (no room in the side-by-side layout); \"Chat about this\" remains the escape hatch. If you recommend a specific option, make it the first option and append \"(Recommended)\" to its label.`,\n\t\"Do not stack multiple ask_user_question calls back-to-back — group all clarifying questions into one invocation.\",\n];\n\nexport function createAskUserQuestionToolDefinition(): ToolDefinition<typeof QuestionParamsSchema, unknown> {\n\tconst guidance = validateGuidanceFields(loadConfig().guidance);\n\treturn {\n\t\tname: \"ask_user_question\",\n\t\tlabel: \"Ask User Question\",\n\t\tdescription: `Ask the user one or more structured questions during execution. Use when you need to:\n1. Gather user preferences or requirements\n2. Clarify ambiguous instructions\n3. Get decisions on implementation choices as you work\n4. Offer choices to the user about what direction to take\n\nUsage notes:\n- Users will always be able to type a custom answer (\"Type something.\" row is appended automatically to every single-select question) or pick \"Chat about this\" to abandon the questionnaire and continue in free-form conversation. Do NOT author \"Other\" / \"Type something.\" / \"Chat about this\" labels yourself — duplicates are rejected at runtime.\n- Use multiSelect: true to allow multiple answers to be selected for a question. The \"Type something.\" row is suppressed on multi-select questions, and is ALSO suppressed on single-select questions where any option carries a \\`preview\\` (the side-by-side layout has no room for inline custom text — \"Chat about this\" remains as the free-form escape hatch).\n- If you recommend a specific option, make that the first option in the list and add \"(Recommended)\" at the end of the label.\n\nPreview feature:\nUse the optional \\`preview\\` field on options when presenting concrete artifacts that users need to visually compare:\n- ASCII mockups of UI layouts or components\n- Code snippets showing different implementations\n- Diagram variations\n- Configuration examples\n\nPreview content is rendered as markdown in a monospace box. Multi-line text with newlines is supported. When any option has a preview, the UI switches to a side-by-side layout with a vertical option list on the left and preview on the right. Do not use previews for simple preference questions where labels and descriptions suffice. Note: previews are only supported for single-select questions (not multiSelect).`,\n\t\tpromptSnippet: guidance.promptSnippet ?? DEFAULT_PROMPT_SNIPPET,\n\t\tpromptGuidelines: guidance.promptGuidelines ?? DEFAULT_PROMPT_GUIDELINES,\n\t\tparameters: QuestionParamsSchema,\n\n\t\tasync execute(_toolCallId, params, signal, _onUpdate, ctx) {\n\t\t\tconst typed = params as unknown as QuestionParams;\n\t\t\tif (!ctx.hasUI) return buildToolResult(ERROR_NO_UI, { answers: [], cancelled: true, error: \"no_ui\" });\n\n\t\t\tconst validation = validateQuestionnaire(typed);\n\t\t\tif (!validation.ok) {\n\t\t\t\treturn buildToolResult(validation.message, {\n\t\t\t\t\tanswers: [],\n\t\t\t\t\tcancelled: true,\n\t\t\t\t\terror: validation.error,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst itemsByTab: WrappingSelectItem[][] = typed.questions.map((q) => buildItemsForQuestion(q));\n\n\t\t\tconst result = await ctx.ui.custom<QuestionnaireResult>((tui, theme, _kb, done) => {\n\t\t\t\tconst session = new QuestionnaireSession({\n\t\t\t\t\ttui,\n\t\t\t\t\ttheme,\n\t\t\t\t\tparams: typed,\n\t\t\t\t\titemsByTab,\n\t\t\t\t\tdone,\n\t\t\t\t});\n\t\t\t\treturn session.component;\n\t\t\t}, { signal });\n\n\t\t\treturn buildQuestionnaireResponse(result, typed);\n\t\t},\n\t};\n}\n\nexport { buildQuestionnaireResponse, buildToolResult };\n"]}
|
|
1
|
+
{"version":3,"file":"ask-user-question.js","sourceRoot":"","sources":["../../../../src/core/tools/ask-user-question/ask-user-question.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC3E,OAAO,EAAE,0BAA0B,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC1F,OAAO,EACN,WAAW,EACX,aAAa,EACb,WAAW,EAIX,oBAAoB,GACpB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAGzE,MAAM,WAAW,GAA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C;wBACxC,GAAG;wBACH,KAAK;wBACL,MAAM,EAAE,KAAK;wBACb,UAAU;wBACV,IAAI;qBACJ,CAAC,CAAC;oBACH,OAAO,OAAO,CAAC,SAAS,CAAC;gBAC1B,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;gBAEf,OAAO,0BAA0B,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;YAClD,CAAC;oBAAS,CAAC;gBACV,GAAG,CAAC,EAAE,CAAC,iBAAiB,EAAE,CAAC,IAAI,CAAC,CAAC;YAClC,CAAC;QACF,CAAC;KACD,CAAC;AACH,CAAC;AAED,OAAO,EAAE,0BAA0B,EAAE,eAAe,EAAE,CAAC","sourcesContent":["import type { ToolDefinition } from \"../../extensions/types.ts\";\nimport { loadConfig, validateGuidanceFields } from \"./config.ts\";\nimport { QuestionnaireSession } from \"./state/questionnaire-session.ts\";\nimport { ROW_INTENT_META, sentinelsToAppend } from \"./state/row-intent.ts\";\nimport { buildQuestionnaireResponse, buildToolResult } from \"./tool/response-envelope.ts\";\nimport {\n\tMAX_OPTIONS,\n\tMAX_QUESTIONS,\n\tMIN_OPTIONS,\n\ttype QuestionData,\n\ttype QuestionnaireResult,\n\ttype QuestionParams,\n\tQuestionParamsSchema,\n} from \"./tool/types.ts\";\nimport { validateQuestionnaire } from \"./tool/validate-questionnaire.ts\";\nimport type { WrappingSelectItem } from \"./view/components/wrapping-select.ts\";\n\nconst ERROR_NO_UI = \"Error: UI not available (running in non-interactive mode)\";\n\nexport function buildItemsForQuestion(question: QuestionData): WrappingSelectItem[] {\n\tconst items: WrappingSelectItem[] = question.options.map((o) => ({\n\t\tkind: \"option\",\n\t\tlabel: o.label,\n\t\tdescription: o.description,\n\t}));\n\tconst hasAnyPreview = question.options.some((o) => typeof o.preview === \"string\" && o.preview.length > 0);\n\tfor (const kind of sentinelsToAppend(question, hasAnyPreview)) {\n\t\titems.push({ kind, label: ROW_INTENT_META[kind].label });\n\t}\n\treturn items;\n}\n\nexport const DEFAULT_PROMPT_SNIPPET = `Ask the user up to ${MAX_QUESTIONS} structured questions (${MIN_OPTIONS}-${MAX_OPTIONS} options each) when requirements are ambiguous`;\nexport const DEFAULT_PROMPT_GUIDELINES: string[] = [\n\t`Use ask_user_question whenever the user's request is underspecified and you cannot proceed without concrete decisions — you can ask up to ${MAX_QUESTIONS} questions per invocation.`,\n\t`Each question MUST have ${MIN_OPTIONS}-${MAX_OPTIONS} options. Every option requires a concise label (1-5 words) and a description explaining what the choice means or its trade-offs. The user can additionally type a custom answer (\"Type something.\" row is appended automatically to single-select questions) or pick \"Chat about this\" to abandon the questionnaire.`,\n\t`Set multiSelect: true when multiple answers are valid; this suppresses the \"Type something.\" row. Provide an options[].preview markdown string when an option benefits from richer side-by-side context (mockups, code snippets, diagrams, configs) — single-select only. NOTE: any non-empty preview on a single-select question ALSO suppresses the \"Type something.\" row (no room in the side-by-side layout); \"Chat about this\" remains the escape hatch. If you recommend a specific option, make it the first option and append \"(Recommended)\" to its label.`,\n\t\"Do not stack multiple ask_user_question calls back-to-back — group all clarifying questions into one invocation.\",\n];\n\nexport function createAskUserQuestionToolDefinition(): ToolDefinition<typeof QuestionParamsSchema, unknown> {\n\tconst guidance = validateGuidanceFields(loadConfig().guidance);\n\treturn {\n\t\tname: \"ask_user_question\",\n\t\tlabel: \"Ask User Question\",\n\t\tdescription: `Ask the user one or more structured questions during execution. Use when you need to:\n1. Gather user preferences or requirements\n2. Clarify ambiguous instructions\n3. Get decisions on implementation choices as you work\n4. Offer choices to the user about what direction to take\n\nUsage notes:\n- Users will always be able to type a custom answer (\"Type something.\" row is appended automatically to every single-select question) or pick \"Chat about this\" to abandon the questionnaire and continue in free-form conversation. Do NOT author \"Other\" / \"Type something.\" / \"Chat about this\" labels yourself — duplicates are rejected at runtime.\n- Use multiSelect: true to allow multiple answers to be selected for a question. The \"Type something.\" row is suppressed on multi-select questions, and is ALSO suppressed on single-select questions where any option carries a \\`preview\\` (the side-by-side layout has no room for inline custom text — \"Chat about this\" remains as the free-form escape hatch).\n- If you recommend a specific option, make that the first option in the list and add \"(Recommended)\" at the end of the label.\n\nPreview feature:\nUse the optional \\`preview\\` field on options when presenting concrete artifacts that users need to visually compare:\n- ASCII mockups of UI layouts or components\n- Code snippets showing different implementations\n- Diagram variations\n- Configuration examples\n\nPreview content is rendered as markdown in a monospace box. Multi-line text with newlines is supported. When any option has a preview, the UI switches to a side-by-side layout with a vertical option list on the left and preview on the right. Do not use previews for simple preference questions where labels and descriptions suffice. Note: previews are only supported for single-select questions (not multiSelect).`,\n\t\tpromptSnippet: guidance.promptSnippet ?? DEFAULT_PROMPT_SNIPPET,\n\t\tpromptGuidelines: guidance.promptGuidelines ?? DEFAULT_PROMPT_GUIDELINES,\n\t\tparameters: QuestionParamsSchema,\n\n\t\tasync execute(_toolCallId, params, signal, _onUpdate, ctx) {\n\t\t\tconst typed = params as unknown as QuestionParams;\n\t\t\tif (!ctx.hasUI) return buildToolResult(ERROR_NO_UI, { answers: [], cancelled: true, error: \"no_ui\" });\n\n\t\t\tconst validation = validateQuestionnaire(typed);\n\t\t\tif (!validation.ok) {\n\t\t\t\treturn buildToolResult(validation.message, {\n\t\t\t\t\tanswers: [],\n\t\t\t\t\tcancelled: true,\n\t\t\t\t\terror: validation.error,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst itemsByTab: WrappingSelectItem[][] = typed.questions.map((q) => buildItemsForQuestion(q));\n\n\t\t\t// Suspend the animated working loader for the lifetime of the blocking dialog.\n\t\t\t//\n\t\t\t// The questionnaire mounts inline, directly below the status/working-loader row.\n\t\t\t// That loader ticks every ~80ms and calls `requestRender()` on each frame. On a\n\t\t\t// short terminal the (tall) side-by-side dialog pushes the loader line above the\n\t\t\t// viewport top, so pi-tui's differential renderer sees `firstChanged < viewportTop`\n\t\t\t// and falls back to a full clear+replay (`\\x1b[2J\\x1b[H\\x1b[3J`) on every tick. The\n\t\t\t// transcript is replayed before the dialog each time, which is the flicker. The\n\t\t\t// loader conveys nothing while we're blocked on human input, so hide it for the\n\t\t\t// duration and restore it once the dialog closes (on every path).\n\t\t\t//\n\t\t\t// Guarded: some hosts (e.g. the workflow stage-UI broker) pass a minimal UI\n\t\t\t// context that only implements `custom`, so treat a missing loader control as a\n\t\t\t// no-op rather than throwing.\n\t\t\tctx.ui.setWorkingVisible?.(false);\n\t\t\ttry {\n\t\t\t\tconst result = await ctx.ui.custom<QuestionnaireResult>((tui, theme, _kb, done) => {\n\t\t\t\t\tconst session = new QuestionnaireSession({\n\t\t\t\t\t\ttui,\n\t\t\t\t\t\ttheme,\n\t\t\t\t\t\tparams: typed,\n\t\t\t\t\t\titemsByTab,\n\t\t\t\t\t\tdone,\n\t\t\t\t\t});\n\t\t\t\t\treturn session.component;\n\t\t\t\t}, { signal });\n\n\t\t\t\treturn buildQuestionnaireResponse(result, typed);\n\t\t\t} finally {\n\t\t\t\tctx.ui.setWorkingVisible?.(true);\n\t\t\t}\n\t\t},\n\t};\n}\n\nexport { buildQuestionnaireResponse, buildToolResult };\n"]}
|
|
@@ -94,6 +94,10 @@ export declare class ChatSessionHost<TExtraEntry extends ChatTranscriptEntryLike
|
|
|
94
94
|
private animationTimer;
|
|
95
95
|
private renderThrottleTimer;
|
|
96
96
|
private bodyViewport;
|
|
97
|
+
private transcriptComponent;
|
|
98
|
+
private transcriptRenderSettingsKey;
|
|
99
|
+
private renderIdentityIds;
|
|
100
|
+
private nextRenderIdentityId;
|
|
97
101
|
private liveChat;
|
|
98
102
|
private editor;
|
|
99
103
|
private optimisticUserSignatureCounts;
|
|
@@ -139,6 +143,10 @@ export declare class ChatSessionHost<TExtraEntry extends ChatTranscriptEntryLike
|
|
|
139
143
|
private streamingWindowedEntry;
|
|
140
144
|
private chatMessageRenderOptions;
|
|
141
145
|
private toolTui;
|
|
146
|
+
private chatRenderSettingsCacheKey;
|
|
147
|
+
private transcriptCacheKey;
|
|
148
|
+
private entryContentCacheKey;
|
|
149
|
+
private renderIdentityKey;
|
|
142
150
|
private pendingMessageLine;
|
|
143
151
|
private abortCompaction;
|
|
144
152
|
private abortBash;
|