@bastani/atomic 0.8.26-alpha.5 → 0.8.26-alpha.6

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.
Files changed (36) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/builtin/intercom/CHANGELOG.md +6 -0
  3. package/dist/builtin/intercom/package.json +1 -1
  4. package/dist/builtin/mcp/CHANGELOG.md +6 -0
  5. package/dist/builtin/mcp/package.json +1 -1
  6. package/dist/builtin/subagents/CHANGELOG.md +6 -0
  7. package/dist/builtin/subagents/package.json +1 -1
  8. package/dist/builtin/subagents/src/runs/background/subagent-runner.ts +48 -10
  9. package/dist/builtin/subagents/src/runs/foreground/execution.ts +30 -9
  10. package/dist/builtin/subagents/src/runs/shared/final-drain.ts +34 -0
  11. package/dist/builtin/subagents/src/runs/shared/model-fallback.ts +416 -7
  12. package/dist/builtin/web-access/CHANGELOG.md +6 -0
  13. package/dist/builtin/web-access/package.json +1 -1
  14. package/dist/builtin/workflows/CHANGELOG.md +6 -0
  15. package/dist/builtin/workflows/package.json +1 -1
  16. package/dist/builtin/workflows/src/extension/index.ts +10 -2
  17. package/dist/builtin/workflows/src/extension/runtime.ts +35 -3
  18. package/dist/builtin/workflows/src/runs/background/status.ts +52 -6
  19. package/dist/builtin/workflows/src/runs/foreground/executor.ts +441 -15
  20. package/dist/builtin/workflows/src/runs/foreground/stage-runner.ts +69 -8
  21. package/dist/builtin/workflows/src/runs/shared/model-fallback.ts +402 -8
  22. package/dist/builtin/workflows/src/shared/persistence-restore.ts +182 -6
  23. package/dist/builtin/workflows/src/shared/persistence-session-entries.ts +76 -6
  24. package/dist/builtin/workflows/src/shared/stage-prompt.ts +33 -2
  25. package/dist/builtin/workflows/src/shared/store-types.ts +31 -0
  26. package/dist/builtin/workflows/src/shared/store.ts +99 -11
  27. package/dist/builtin/workflows/src/shared/workflow-failures.ts +758 -132
  28. package/dist/core/tools/ask-user-question/tool/format-answer.d.ts +5 -5
  29. package/dist/core/tools/ask-user-question/tool/format-answer.d.ts.map +1 -1
  30. package/dist/core/tools/ask-user-question/tool/format-answer.js +5 -5
  31. package/dist/core/tools/ask-user-question/tool/format-answer.js.map +1 -1
  32. package/dist/core/tools/ask-user-question/tool/response-envelope.d.ts +16 -3
  33. package/dist/core/tools/ask-user-question/tool/response-envelope.d.ts.map +1 -1
  34. package/dist/core/tools/ask-user-question/tool/response-envelope.js +21 -3
  35. package/dist/core/tools/ask-user-question/tool/response-envelope.js.map +1 -1
  36. package/package.json +1 -1
@@ -1,10 +1,10 @@
1
1
  import type { QuestionAnswer } from "./types.ts";
2
2
  /**
3
- * Continuation message used in the LLM-facing envelope. Two-sentence imperative form
4
- * the model needs the "Continue the conversation…" directive to know what to do next
5
- * after the user picks chat instead of answering.
3
+ * Continuation message used in the LLM-facing envelope. Two-sentence form
4
+ * the model needs the "Stopwait…" directive to know what to do next after the
5
+ * user picks chat instead of answering.
6
6
  */
7
- export declare const CHAT_CONTINUATION_MESSAGE = "User wants to chat about this. Continue the conversation to help them decide.";
7
+ export declare const CHAT_CONTINUATION_MESSAGE = "User wants to chat about this. Stop the current task flow and wait for the user's next message.";
8
8
  /**
9
9
  * One-sentence summary form shown in the on-screen Submit-tab review pane. The dialog
10
10
  * already shows the question; the imperative continuation directive belongs in the
@@ -20,7 +20,7 @@ export declare const NO_INPUT_PLACEHOLDER = "(no input)";
20
20
  export type FormatAnswerVariant = "summary" | "envelope";
21
21
  /**
22
22
  * Format a `QuestionAnswer` to its scalar string form. Variant controls only the
23
- * `kind: "chat"` branch — the envelope's two-sentence imperative is needed by the LLM,
23
+ * `kind: "chat"` branch — the envelope's stop/wait directive is needed by the LLM,
24
24
  * the dialog summary's one-sentence reminder is not. All other branches return identical
25
25
  * strings; the `kind: "custom"` empty-string handling and the option fallback both unify
26
26
  * on `NO_INPUT_PLACEHOLDER`. Switch is exhaustive — non-`void` return enforces every
@@ -1 +1 @@
1
- {"version":3,"file":"format-answer.d.ts","sourceRoot":"","sources":["../../../../../src/core/tools/ask-user-question/tool/format-answer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,kFAC0C,CAAC;AAEjF;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,kCAAkC,CAAC;AAEpE;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,eAAe,CAAC;AAEjD,MAAM,MAAM,mBAAmB,GAAG,SAAS,GAAG,UAAU,CAAC;AAEzD;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,cAAc,EAAE,OAAO,EAAE,mBAAmB,GAAG,MAAM,CAW1F","sourcesContent":["import type { QuestionAnswer } from \"./types.ts\";\n\n/**\n * Continuation message used in the LLM-facing envelope. Two-sentence imperative form\n * the model needs the \"Continue the conversation…\" directive to know what to do next\n * after the user picks chat instead of answering.\n */\nexport const CHAT_CONTINUATION_MESSAGE =\n\t\"User wants to chat about this. Continue the conversation to help them decide.\";\n\n/**\n * One-sentence summary form shown in the on-screen Submit-tab review pane. The dialog\n * already shows the question; the imperative continuation directive belongs in the\n * envelope, not in the user-facing summary box.\n */\nexport const CHAT_SUMMARY_MESSAGE = \"User wants to chat about this\";\n\n/**\n * Placeholder for empty / null answer text. Used uniformly across both variants — the\n * earlier `(no answer)` fallback in the dialog summary was accidental drift; tests pin\n * `(no input)` only.\n */\nexport const NO_INPUT_PLACEHOLDER = \"(no input)\";\n\nexport type FormatAnswerVariant = \"summary\" | \"envelope\";\n\n/**\n * Format a `QuestionAnswer` to its scalar string form. Variant controls only the\n * `kind: \"chat\"` branch — the envelope's two-sentence imperative is needed by the LLM,\n * the dialog summary's one-sentence reminder is not. All other branches return identical\n * strings; the `kind: \"custom\"` empty-string handling and the option fallback both unify\n * on `NO_INPUT_PLACEHOLDER`. Switch is exhaustive — non-`void` return enforces every\n * variant is handled.\n */\nexport function formatAnswerScalar(a: QuestionAnswer, variant: FormatAnswerVariant): string {\n\tswitch (a.kind) {\n\t\tcase \"chat\":\n\t\t\treturn variant === \"envelope\" ? CHAT_CONTINUATION_MESSAGE : CHAT_SUMMARY_MESSAGE;\n\t\tcase \"multi\":\n\t\t\treturn a.selected && a.selected.length > 0 ? a.selected.join(\", \") : NO_INPUT_PLACEHOLDER;\n\t\tcase \"custom\":\n\t\t\treturn a.answer && a.answer.length > 0 ? a.answer : NO_INPUT_PLACEHOLDER;\n\t\tcase \"option\":\n\t\t\treturn a.answer ?? NO_INPUT_PLACEHOLDER;\n\t}\n}\n"]}
1
+ {"version":3,"file":"format-answer.d.ts","sourceRoot":"","sources":["../../../../../src/core/tools/ask-user-question/tool/format-answer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,oGAC4D,CAAC;AAEnG;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,kCAAkC,CAAC;AAEpE;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,eAAe,CAAC;AAEjD,MAAM,MAAM,mBAAmB,GAAG,SAAS,GAAG,UAAU,CAAC;AAEzD;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,cAAc,EAAE,OAAO,EAAE,mBAAmB,GAAG,MAAM,CAW1F","sourcesContent":["import type { QuestionAnswer } from \"./types.ts\";\n\n/**\n * Continuation message used in the LLM-facing envelope. Two-sentence form —\n * the model needs the \"Stop…wait…\" directive to know what to do next after the\n * user picks chat instead of answering.\n */\nexport const CHAT_CONTINUATION_MESSAGE =\n\t\"User wants to chat about this. Stop the current task flow and wait for the user's next message.\";\n\n/**\n * One-sentence summary form shown in the on-screen Submit-tab review pane. The dialog\n * already shows the question; the imperative continuation directive belongs in the\n * envelope, not in the user-facing summary box.\n */\nexport const CHAT_SUMMARY_MESSAGE = \"User wants to chat about this\";\n\n/**\n * Placeholder for empty / null answer text. Used uniformly across both variants — the\n * earlier `(no answer)` fallback in the dialog summary was accidental drift; tests pin\n * `(no input)` only.\n */\nexport const NO_INPUT_PLACEHOLDER = \"(no input)\";\n\nexport type FormatAnswerVariant = \"summary\" | \"envelope\";\n\n/**\n * Format a `QuestionAnswer` to its scalar string form. Variant controls only the\n * `kind: \"chat\"` branch — the envelope's stop/wait directive is needed by the LLM,\n * the dialog summary's one-sentence reminder is not. All other branches return identical\n * strings; the `kind: \"custom\"` empty-string handling and the option fallback both unify\n * on `NO_INPUT_PLACEHOLDER`. Switch is exhaustive — non-`void` return enforces every\n * variant is handled.\n */\nexport function formatAnswerScalar(a: QuestionAnswer, variant: FormatAnswerVariant): string {\n\tswitch (a.kind) {\n\t\tcase \"chat\":\n\t\t\treturn variant === \"envelope\" ? CHAT_CONTINUATION_MESSAGE : CHAT_SUMMARY_MESSAGE;\n\t\tcase \"multi\":\n\t\t\treturn a.selected && a.selected.length > 0 ? a.selected.join(\", \") : NO_INPUT_PLACEHOLDER;\n\t\tcase \"custom\":\n\t\t\treturn a.answer && a.answer.length > 0 ? a.answer : NO_INPUT_PLACEHOLDER;\n\t\tcase \"option\":\n\t\t\treturn a.answer ?? NO_INPUT_PLACEHOLDER;\n\t}\n}\n"]}
@@ -1,9 +1,9 @@
1
1
  /**
2
- * Continuation message used in the LLM-facing envelope. Two-sentence imperative form
3
- * the model needs the "Continue the conversation…" directive to know what to do next
4
- * after the user picks chat instead of answering.
2
+ * Continuation message used in the LLM-facing envelope. Two-sentence form
3
+ * the model needs the "Stopwait…" directive to know what to do next after the
4
+ * user picks chat instead of answering.
5
5
  */
6
- export const CHAT_CONTINUATION_MESSAGE = "User wants to chat about this. Continue the conversation to help them decide.";
6
+ export const CHAT_CONTINUATION_MESSAGE = "User wants to chat about this. Stop the current task flow and wait for the user's next message.";
7
7
  /**
8
8
  * One-sentence summary form shown in the on-screen Submit-tab review pane. The dialog
9
9
  * already shows the question; the imperative continuation directive belongs in the
@@ -18,7 +18,7 @@ export const CHAT_SUMMARY_MESSAGE = "User wants to chat about this";
18
18
  export const NO_INPUT_PLACEHOLDER = "(no input)";
19
19
  /**
20
20
  * Format a `QuestionAnswer` to its scalar string form. Variant controls only the
21
- * `kind: "chat"` branch — the envelope's two-sentence imperative is needed by the LLM,
21
+ * `kind: "chat"` branch — the envelope's stop/wait directive is needed by the LLM,
22
22
  * the dialog summary's one-sentence reminder is not. All other branches return identical
23
23
  * strings; the `kind: "custom"` empty-string handling and the option fallback both unify
24
24
  * on `NO_INPUT_PLACEHOLDER`. Switch is exhaustive — non-`void` return enforces every
@@ -1 +1 @@
1
- {"version":3,"file":"format-answer.js","sourceRoot":"","sources":["../../../../../src/core/tools/ask-user-question/tool/format-answer.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,CAAC,MAAM,yBAAyB,GACrC,+EAA+E,CAAC;AAEjF;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,+BAA+B,CAAC;AAEpE;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,YAAY,CAAC;AAIjD;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CAAC,CAAiB,EAAE,OAA4B;IACjF,QAAQ,CAAC,CAAC,IAAI,EAAE,CAAC;QAChB,KAAK,MAAM;YACV,OAAO,OAAO,KAAK,UAAU,CAAC,CAAC,CAAC,yBAAyB,CAAC,CAAC,CAAC,oBAAoB,CAAC;QAClF,KAAK,OAAO;YACX,OAAO,CAAC,CAAC,QAAQ,IAAI,CAAC,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,oBAAoB,CAAC;QAC3F,KAAK,QAAQ;YACZ,OAAO,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,oBAAoB,CAAC;QAC1E,KAAK,QAAQ;YACZ,OAAO,CAAC,CAAC,MAAM,IAAI,oBAAoB,CAAC;IAC1C,CAAC;AACF,CAAC","sourcesContent":["import type { QuestionAnswer } from \"./types.ts\";\n\n/**\n * Continuation message used in the LLM-facing envelope. Two-sentence imperative form\n * the model needs the \"Continue the conversation…\" directive to know what to do next\n * after the user picks chat instead of answering.\n */\nexport const CHAT_CONTINUATION_MESSAGE =\n\t\"User wants to chat about this. Continue the conversation to help them decide.\";\n\n/**\n * One-sentence summary form shown in the on-screen Submit-tab review pane. The dialog\n * already shows the question; the imperative continuation directive belongs in the\n * envelope, not in the user-facing summary box.\n */\nexport const CHAT_SUMMARY_MESSAGE = \"User wants to chat about this\";\n\n/**\n * Placeholder for empty / null answer text. Used uniformly across both variants — the\n * earlier `(no answer)` fallback in the dialog summary was accidental drift; tests pin\n * `(no input)` only.\n */\nexport const NO_INPUT_PLACEHOLDER = \"(no input)\";\n\nexport type FormatAnswerVariant = \"summary\" | \"envelope\";\n\n/**\n * Format a `QuestionAnswer` to its scalar string form. Variant controls only the\n * `kind: \"chat\"` branch — the envelope's two-sentence imperative is needed by the LLM,\n * the dialog summary's one-sentence reminder is not. All other branches return identical\n * strings; the `kind: \"custom\"` empty-string handling and the option fallback both unify\n * on `NO_INPUT_PLACEHOLDER`. Switch is exhaustive — non-`void` return enforces every\n * variant is handled.\n */\nexport function formatAnswerScalar(a: QuestionAnswer, variant: FormatAnswerVariant): string {\n\tswitch (a.kind) {\n\t\tcase \"chat\":\n\t\t\treturn variant === \"envelope\" ? CHAT_CONTINUATION_MESSAGE : CHAT_SUMMARY_MESSAGE;\n\t\tcase \"multi\":\n\t\t\treturn a.selected && a.selected.length > 0 ? a.selected.join(\", \") : NO_INPUT_PLACEHOLDER;\n\t\tcase \"custom\":\n\t\t\treturn a.answer && a.answer.length > 0 ? a.answer : NO_INPUT_PLACEHOLDER;\n\t\tcase \"option\":\n\t\t\treturn a.answer ?? NO_INPUT_PLACEHOLDER;\n\t}\n}\n"]}
1
+ {"version":3,"file":"format-answer.js","sourceRoot":"","sources":["../../../../../src/core/tools/ask-user-question/tool/format-answer.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,CAAC,MAAM,yBAAyB,GACrC,iGAAiG,CAAC;AAEnG;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,+BAA+B,CAAC;AAEpE;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,YAAY,CAAC;AAIjD;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CAAC,CAAiB,EAAE,OAA4B;IACjF,QAAQ,CAAC,CAAC,IAAI,EAAE,CAAC;QAChB,KAAK,MAAM;YACV,OAAO,OAAO,KAAK,UAAU,CAAC,CAAC,CAAC,yBAAyB,CAAC,CAAC,CAAC,oBAAoB,CAAC;QAClF,KAAK,OAAO;YACX,OAAO,CAAC,CAAC,QAAQ,IAAI,CAAC,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,oBAAoB,CAAC;QAC3F,KAAK,QAAQ;YACZ,OAAO,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,oBAAoB,CAAC;QAC1E,KAAK,QAAQ;YACZ,OAAO,CAAC,CAAC,MAAM,IAAI,oBAAoB,CAAC;IAC1C,CAAC;AACF,CAAC","sourcesContent":["import type { QuestionAnswer } from \"./types.ts\";\n\n/**\n * Continuation message used in the LLM-facing envelope. Two-sentence form —\n * the model needs the \"Stop…wait…\" directive to know what to do next after the\n * user picks chat instead of answering.\n */\nexport const CHAT_CONTINUATION_MESSAGE =\n\t\"User wants to chat about this. Stop the current task flow and wait for the user's next message.\";\n\n/**\n * One-sentence summary form shown in the on-screen Submit-tab review pane. The dialog\n * already shows the question; the imperative continuation directive belongs in the\n * envelope, not in the user-facing summary box.\n */\nexport const CHAT_SUMMARY_MESSAGE = \"User wants to chat about this\";\n\n/**\n * Placeholder for empty / null answer text. Used uniformly across both variants — the\n * earlier `(no answer)` fallback in the dialog summary was accidental drift; tests pin\n * `(no input)` only.\n */\nexport const NO_INPUT_PLACEHOLDER = \"(no input)\";\n\nexport type FormatAnswerVariant = \"summary\" | \"envelope\";\n\n/**\n * Format a `QuestionAnswer` to its scalar string form. Variant controls only the\n * `kind: \"chat\"` branch — the envelope's stop/wait directive is needed by the LLM,\n * the dialog summary's one-sentence reminder is not. All other branches return identical\n * strings; the `kind: \"custom\"` empty-string handling and the option fallback both unify\n * on `NO_INPUT_PLACEHOLDER`. Switch is exhaustive — non-`void` return enforces every\n * variant is handled.\n */\nexport function formatAnswerScalar(a: QuestionAnswer, variant: FormatAnswerVariant): string {\n\tswitch (a.kind) {\n\t\tcase \"chat\":\n\t\t\treturn variant === \"envelope\" ? CHAT_CONTINUATION_MESSAGE : CHAT_SUMMARY_MESSAGE;\n\t\tcase \"multi\":\n\t\t\treturn a.selected && a.selected.length > 0 ? a.selected.join(\", \") : NO_INPUT_PLACEHOLDER;\n\t\tcase \"custom\":\n\t\t\treturn a.answer && a.answer.length > 0 ? a.answer : NO_INPUT_PLACEHOLDER;\n\t\tcase \"option\":\n\t\t\treturn a.answer ?? NO_INPUT_PLACEHOLDER;\n\t}\n}\n"]}
@@ -2,10 +2,19 @@ import type { QuestionAnswer, QuestionnaireResult, QuestionParams } from "./type
2
2
  export declare const DECLINE_MESSAGE = "User declined to answer questions";
3
3
  export declare const ENVELOPE_PREFIX = "User has answered your questions:";
4
4
  export declare const ENVELOPE_SUFFIX = "You can now continue with the user's answers in mind.";
5
+ /**
6
+ * True when any answer in the result carries `kind: "chat"`.
7
+ * Used by `buildQuestionnaireResponse` to switch to the terminate path.
8
+ */
9
+ export declare function hasChatAnswer(result: QuestionnaireResult): boolean;
5
10
  /**
6
11
  * Map a `QuestionnaireResult` (or null/cancelled) to the LLM-facing tool envelope.
7
- * Pure of `(result, params)`; cancelled and "no segments" both fall to `DECLINE_MESSAGE`
8
- * so the model sees a single canonical "didn't answer" signal regardless of why.
12
+ * Pure of `(result, params)`; cancelled and non-chat "no segments" both fall to
13
+ * `DECLINE_MESSAGE` so the model sees a single canonical "didn't answer" signal
14
+ * regardless of why.
15
+ *
16
+ * Chat rule: when any non-cancelled answer is `kind: "chat"`, the result carries
17
+ * `terminate: true` and stop/wait wording instead of the generic continuation suffix.
9
18
  */
10
19
  export declare function buildQuestionnaireResponse(result: QuestionnaireResult | null | undefined, params: QuestionParams): {
11
20
  content: {
@@ -13,17 +22,21 @@ export declare function buildQuestionnaireResponse(result: QuestionnaireResult |
13
22
  text: string;
14
23
  }[];
15
24
  details: QuestionnaireResult;
25
+ terminate?: boolean | undefined;
16
26
  };
17
27
  /**
18
28
  * Format a single answer segment for the envelope. Pure of `a`. The `"Q"="A"` shape and
19
29
  * the optional `selected preview:` / `user notes:` suffixes are pinned by envelope tests.
20
30
  */
21
31
  export declare function buildAnswerSegment(a: QuestionAnswer): string;
22
- export declare function buildToolResult(text: string, details: QuestionnaireResult): {
32
+ export declare function buildToolResult(text: string, details: QuestionnaireResult, options?: {
33
+ terminate?: boolean;
34
+ }): {
23
35
  content: {
24
36
  type: "text";
25
37
  text: string;
26
38
  }[];
27
39
  details: QuestionnaireResult;
40
+ terminate?: boolean | undefined;
28
41
  };
29
42
  //# sourceMappingURL=response-envelope.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"response-envelope.d.ts","sourceRoot":"","sources":["../../../../../src/core/tools/ask-user-question/tool/response-envelope.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEtF,eAAO,MAAM,eAAe,sCAAsC,CAAC;AACnE,eAAO,MAAM,eAAe,sCAAsC,CAAC;AACnE,eAAO,MAAM,eAAe,0DAA0D,CAAC;AAEvF;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,mBAAmB,GAAG,IAAI,GAAG,SAAS,EAAE,MAAM,EAAE,cAAc;;cA+B7F,MAAM;;;;EAfzB;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,cAAc,GAAG,MAAM,CAK5D;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,mBAAmB;;cAEtD,MAAM;;;;EAGzB","sourcesContent":["import { formatAnswerScalar } from \"./format-answer.ts\";\nimport type { QuestionAnswer, QuestionnaireResult, QuestionParams } from \"./types.ts\";\n\nexport const DECLINE_MESSAGE = \"User declined to answer questions\";\nexport const ENVELOPE_PREFIX = \"User has answered your questions:\";\nexport const ENVELOPE_SUFFIX = \"You can now continue with the user's answers in mind.\";\n\n/**\n * Map a `QuestionnaireResult` (or null/cancelled) to the LLM-facing tool envelope.\n * Pure of `(result, params)`; cancelled and \"no segments\" both fall to `DECLINE_MESSAGE`\n * so the model sees a single canonical \"didn't answer\" signal regardless of why.\n */\nexport function buildQuestionnaireResponse(result: QuestionnaireResult | null | undefined, params: QuestionParams) {\n\tif (!result || result.cancelled) {\n\t\treturn buildToolResult(DECLINE_MESSAGE, {\n\t\t\tanswers: result?.answers ?? [],\n\t\t\tcancelled: true,\n\t\t});\n\t}\n\tconst segments: string[] = [];\n\tfor (let i = 0; i < params.questions.length; i++) {\n\t\tconst a = result.answers.find((x) => x.questionIndex === i);\n\t\tif (a) segments.push(buildAnswerSegment(a));\n\t}\n\tif (segments.length === 0) {\n\t\treturn buildToolResult(DECLINE_MESSAGE, { answers: result.answers, cancelled: true });\n\t}\n\treturn buildToolResult(`${ENVELOPE_PREFIX} ${segments.join(\" \")} ${ENVELOPE_SUFFIX}`, result);\n}\n\n/**\n * Format a single answer segment for the envelope. Pure of `a`. The `\"Q\"=\"A\"` shape and\n * the optional `selected preview:` / `user notes:` suffixes are pinned by envelope tests.\n */\nexport function buildAnswerSegment(a: QuestionAnswer): string {\n\tconst parts: string[] = [`\"${a.question}\"=\"${formatAnswerScalar(a, \"envelope\")}\"`];\n\tif (a.preview && a.preview.length > 0) parts.push(`selected preview: ${a.preview}`);\n\tif (a.notes && a.notes.length > 0) parts.push(`user notes: ${a.notes}`);\n\treturn `${parts.join(\". \")}.`;\n}\n\nexport function buildToolResult(text: string, details: QuestionnaireResult) {\n\treturn {\n\t\tcontent: [{ type: \"text\" as const, text }],\n\t\tdetails,\n\t};\n}\n"]}
1
+ {"version":3,"file":"response-envelope.d.ts","sourceRoot":"","sources":["../../../../../src/core/tools/ask-user-question/tool/response-envelope.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEtF,eAAO,MAAM,eAAe,sCAAsC,CAAC;AACnE,eAAO,MAAM,eAAe,sCAAsC,CAAC;AACnE,eAAO,MAAM,eAAe,0DAA0D,CAAC;AAIvF;;;GAGG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAElE;AAED;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,mBAAmB,GAAG,IAAI,GAAG,SAAS,EAAE,MAAM,EAAE,cAAc;;cAoC7F,MAAM;;;;;EAfzB;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,cAAc,GAAG,MAAM,CAK5D;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,mBAAmB,EAAE,OAAO,CAAC,EAAE;IAAE,SAAS,CAAC,EAAE,OAAO,CAAA;CAAE;;cAEzF,MAAM;;;;;EAIzB","sourcesContent":["import { formatAnswerScalar } from \"./format-answer.ts\";\nimport type { QuestionAnswer, QuestionnaireResult, QuestionParams } from \"./types.ts\";\n\nexport const DECLINE_MESSAGE = \"User declined to answer questions\";\nexport const ENVELOPE_PREFIX = \"User has answered your questions:\";\nexport const ENVELOPE_SUFFIX = \"You can now continue with the user's answers in mind.\";\nconst CHAT_TERMINATION_DIRECTIVE =\n\t\"User wants to chat about this before choosing. Stop the current task flow and wait for the user's next message.\";\n\n/**\n * True when any answer in the result carries `kind: \"chat\"`.\n * Used by `buildQuestionnaireResponse` to switch to the terminate path.\n */\nexport function hasChatAnswer(result: QuestionnaireResult): boolean {\n\treturn result.answers.some((a) => a.kind === \"chat\");\n}\n\n/**\n * Map a `QuestionnaireResult` (or null/cancelled) to the LLM-facing tool envelope.\n * Pure of `(result, params)`; cancelled and non-chat \"no segments\" both fall to\n * `DECLINE_MESSAGE` so the model sees a single canonical \"didn't answer\" signal\n * regardless of why.\n *\n * Chat rule: when any non-cancelled answer is `kind: \"chat\"`, the result carries\n * `terminate: true` and stop/wait wording instead of the generic continuation suffix.\n */\nexport function buildQuestionnaireResponse(result: QuestionnaireResult | null | undefined, params: QuestionParams) {\n\tif (!result || result.cancelled) {\n\t\treturn buildToolResult(DECLINE_MESSAGE, {\n\t\t\tanswers: result?.answers ?? [],\n\t\t\tcancelled: true,\n\t\t});\n\t}\n\tconst containsChatAnswer = hasChatAnswer(result);\n\tconst segments: string[] = [];\n\tfor (let i = 0; i < params.questions.length; i++) {\n\t\tconst a = result.answers.find((x) => x.questionIndex === i);\n\t\tif (a) segments.push(buildAnswerSegment(a));\n\t}\n\tif (containsChatAnswer) {\n\t\tconst answerSegments = segments.length > 0 ? ` ${segments.join(\" \")}` : \"\";\n\t\treturn buildToolResult(`${CHAT_TERMINATION_DIRECTIVE}${answerSegments}`, result, { terminate: true });\n\t}\n\tif (segments.length === 0) {\n\t\treturn buildToolResult(DECLINE_MESSAGE, { answers: result.answers, cancelled: true });\n\t}\n\treturn buildToolResult(`${ENVELOPE_PREFIX} ${segments.join(\" \")} ${ENVELOPE_SUFFIX}`, result);\n}\n\n/**\n * Format a single answer segment for the envelope. Pure of `a`. The `\"Q\"=\"A\"` shape and\n * the optional `selected preview:` / `user notes:` suffixes are pinned by envelope tests.\n */\nexport function buildAnswerSegment(a: QuestionAnswer): string {\n\tconst parts: string[] = [`\"${a.question}\"=\"${formatAnswerScalar(a, \"envelope\")}\"`];\n\tif (a.preview && a.preview.length > 0) parts.push(`selected preview: ${a.preview}`);\n\tif (a.notes && a.notes.length > 0) parts.push(`user notes: ${a.notes}`);\n\treturn `${parts.join(\". \")}.`;\n}\n\nexport function buildToolResult(text: string, details: QuestionnaireResult, options?: { terminate?: boolean }) {\n\treturn {\n\t\tcontent: [{ type: \"text\" as const, text }],\n\t\tdetails,\n\t\t...(options?.terminate === true ? { terminate: true } : {}),\n\t};\n}\n"]}
@@ -2,10 +2,22 @@ import { formatAnswerScalar } from "./format-answer.js";
2
2
  export const DECLINE_MESSAGE = "User declined to answer questions";
3
3
  export const ENVELOPE_PREFIX = "User has answered your questions:";
4
4
  export const ENVELOPE_SUFFIX = "You can now continue with the user's answers in mind.";
5
+ const CHAT_TERMINATION_DIRECTIVE = "User wants to chat about this before choosing. Stop the current task flow and wait for the user's next message.";
6
+ /**
7
+ * True when any answer in the result carries `kind: "chat"`.
8
+ * Used by `buildQuestionnaireResponse` to switch to the terminate path.
9
+ */
10
+ export function hasChatAnswer(result) {
11
+ return result.answers.some((a) => a.kind === "chat");
12
+ }
5
13
  /**
6
14
  * Map a `QuestionnaireResult` (or null/cancelled) to the LLM-facing tool envelope.
7
- * Pure of `(result, params)`; cancelled and "no segments" both fall to `DECLINE_MESSAGE`
8
- * so the model sees a single canonical "didn't answer" signal regardless of why.
15
+ * Pure of `(result, params)`; cancelled and non-chat "no segments" both fall to
16
+ * `DECLINE_MESSAGE` so the model sees a single canonical "didn't answer" signal
17
+ * regardless of why.
18
+ *
19
+ * Chat rule: when any non-cancelled answer is `kind: "chat"`, the result carries
20
+ * `terminate: true` and stop/wait wording instead of the generic continuation suffix.
9
21
  */
10
22
  export function buildQuestionnaireResponse(result, params) {
11
23
  if (!result || result.cancelled) {
@@ -14,12 +26,17 @@ export function buildQuestionnaireResponse(result, params) {
14
26
  cancelled: true,
15
27
  });
16
28
  }
29
+ const containsChatAnswer = hasChatAnswer(result);
17
30
  const segments = [];
18
31
  for (let i = 0; i < params.questions.length; i++) {
19
32
  const a = result.answers.find((x) => x.questionIndex === i);
20
33
  if (a)
21
34
  segments.push(buildAnswerSegment(a));
22
35
  }
36
+ if (containsChatAnswer) {
37
+ const answerSegments = segments.length > 0 ? ` ${segments.join(" ")}` : "";
38
+ return buildToolResult(`${CHAT_TERMINATION_DIRECTIVE}${answerSegments}`, result, { terminate: true });
39
+ }
23
40
  if (segments.length === 0) {
24
41
  return buildToolResult(DECLINE_MESSAGE, { answers: result.answers, cancelled: true });
25
42
  }
@@ -37,10 +54,11 @@ export function buildAnswerSegment(a) {
37
54
  parts.push(`user notes: ${a.notes}`);
38
55
  return `${parts.join(". ")}.`;
39
56
  }
40
- export function buildToolResult(text, details) {
57
+ export function buildToolResult(text, details, options) {
41
58
  return {
42
59
  content: [{ type: "text", text }],
43
60
  details,
61
+ ...(options?.terminate === true ? { terminate: true } : {}),
44
62
  };
45
63
  }
46
64
  //# sourceMappingURL=response-envelope.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"response-envelope.js","sourceRoot":"","sources":["../../../../../src/core/tools/ask-user-question/tool/response-envelope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAGxD,MAAM,CAAC,MAAM,eAAe,GAAG,mCAAmC,CAAC;AACnE,MAAM,CAAC,MAAM,eAAe,GAAG,mCAAmC,CAAC;AACnE,MAAM,CAAC,MAAM,eAAe,GAAG,uDAAuD,CAAC;AAEvF;;;;GAIG;AACH,MAAM,UAAU,0BAA0B,CAAC,MAA8C,EAAE,MAAsB;IAChH,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;QACjC,OAAO,eAAe,CAAC,eAAe,EAAE;YACvC,OAAO,EAAE,MAAM,EAAE,OAAO,IAAI,EAAE;YAC9B,SAAS,EAAE,IAAI;SACf,CAAC,CAAC;IACJ,CAAC;IACD,MAAM,QAAQ,GAAa,EAAE,CAAC;IAC9B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAClD,MAAM,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,KAAK,CAAC,CAAC,CAAC;QAC5D,IAAI,CAAC;YAAE,QAAQ,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7C,CAAC;IACD,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC3B,OAAO,eAAe,CAAC,eAAe,EAAE,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACvF,CAAC;IACD,OAAO,eAAe,CAAC,GAAG,eAAe,IAAI,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,eAAe,EAAE,EAAE,MAAM,CAAC,CAAC;AAC/F,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAC,CAAiB;IACnD,MAAM,KAAK,GAAa,CAAC,IAAI,CAAC,CAAC,QAAQ,MAAM,kBAAkB,CAAC,CAAC,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC;IACnF,IAAI,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC;QAAE,KAAK,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;IACpF,IAAI,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC;QAAE,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;IACxE,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;AAC/B,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,IAAY,EAAE,OAA4B;IACzE,OAAO;QACN,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,CAAC;QAC1C,OAAO;KACP,CAAC;AACH,CAAC","sourcesContent":["import { formatAnswerScalar } from \"./format-answer.ts\";\nimport type { QuestionAnswer, QuestionnaireResult, QuestionParams } from \"./types.ts\";\n\nexport const DECLINE_MESSAGE = \"User declined to answer questions\";\nexport const ENVELOPE_PREFIX = \"User has answered your questions:\";\nexport const ENVELOPE_SUFFIX = \"You can now continue with the user's answers in mind.\";\n\n/**\n * Map a `QuestionnaireResult` (or null/cancelled) to the LLM-facing tool envelope.\n * Pure of `(result, params)`; cancelled and \"no segments\" both fall to `DECLINE_MESSAGE`\n * so the model sees a single canonical \"didn't answer\" signal regardless of why.\n */\nexport function buildQuestionnaireResponse(result: QuestionnaireResult | null | undefined, params: QuestionParams) {\n\tif (!result || result.cancelled) {\n\t\treturn buildToolResult(DECLINE_MESSAGE, {\n\t\t\tanswers: result?.answers ?? [],\n\t\t\tcancelled: true,\n\t\t});\n\t}\n\tconst segments: string[] = [];\n\tfor (let i = 0; i < params.questions.length; i++) {\n\t\tconst a = result.answers.find((x) => x.questionIndex === i);\n\t\tif (a) segments.push(buildAnswerSegment(a));\n\t}\n\tif (segments.length === 0) {\n\t\treturn buildToolResult(DECLINE_MESSAGE, { answers: result.answers, cancelled: true });\n\t}\n\treturn buildToolResult(`${ENVELOPE_PREFIX} ${segments.join(\" \")} ${ENVELOPE_SUFFIX}`, result);\n}\n\n/**\n * Format a single answer segment for the envelope. Pure of `a`. The `\"Q\"=\"A\"` shape and\n * the optional `selected preview:` / `user notes:` suffixes are pinned by envelope tests.\n */\nexport function buildAnswerSegment(a: QuestionAnswer): string {\n\tconst parts: string[] = [`\"${a.question}\"=\"${formatAnswerScalar(a, \"envelope\")}\"`];\n\tif (a.preview && a.preview.length > 0) parts.push(`selected preview: ${a.preview}`);\n\tif (a.notes && a.notes.length > 0) parts.push(`user notes: ${a.notes}`);\n\treturn `${parts.join(\". \")}.`;\n}\n\nexport function buildToolResult(text: string, details: QuestionnaireResult) {\n\treturn {\n\t\tcontent: [{ type: \"text\" as const, text }],\n\t\tdetails,\n\t};\n}\n"]}
1
+ {"version":3,"file":"response-envelope.js","sourceRoot":"","sources":["../../../../../src/core/tools/ask-user-question/tool/response-envelope.ts"],"names":[],"mappings":"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","sourcesContent":["import { formatAnswerScalar } from \"./format-answer.ts\";\nimport type { QuestionAnswer, QuestionnaireResult, QuestionParams } from \"./types.ts\";\n\nexport const DECLINE_MESSAGE = \"User declined to answer questions\";\nexport const ENVELOPE_PREFIX = \"User has answered your questions:\";\nexport const ENVELOPE_SUFFIX = \"You can now continue with the user's answers in mind.\";\nconst CHAT_TERMINATION_DIRECTIVE =\n\t\"User wants to chat about this before choosing. Stop the current task flow and wait for the user's next message.\";\n\n/**\n * True when any answer in the result carries `kind: \"chat\"`.\n * Used by `buildQuestionnaireResponse` to switch to the terminate path.\n */\nexport function hasChatAnswer(result: QuestionnaireResult): boolean {\n\treturn result.answers.some((a) => a.kind === \"chat\");\n}\n\n/**\n * Map a `QuestionnaireResult` (or null/cancelled) to the LLM-facing tool envelope.\n * Pure of `(result, params)`; cancelled and non-chat \"no segments\" both fall to\n * `DECLINE_MESSAGE` so the model sees a single canonical \"didn't answer\" signal\n * regardless of why.\n *\n * Chat rule: when any non-cancelled answer is `kind: \"chat\"`, the result carries\n * `terminate: true` and stop/wait wording instead of the generic continuation suffix.\n */\nexport function buildQuestionnaireResponse(result: QuestionnaireResult | null | undefined, params: QuestionParams) {\n\tif (!result || result.cancelled) {\n\t\treturn buildToolResult(DECLINE_MESSAGE, {\n\t\t\tanswers: result?.answers ?? [],\n\t\t\tcancelled: true,\n\t\t});\n\t}\n\tconst containsChatAnswer = hasChatAnswer(result);\n\tconst segments: string[] = [];\n\tfor (let i = 0; i < params.questions.length; i++) {\n\t\tconst a = result.answers.find((x) => x.questionIndex === i);\n\t\tif (a) segments.push(buildAnswerSegment(a));\n\t}\n\tif (containsChatAnswer) {\n\t\tconst answerSegments = segments.length > 0 ? ` ${segments.join(\" \")}` : \"\";\n\t\treturn buildToolResult(`${CHAT_TERMINATION_DIRECTIVE}${answerSegments}`, result, { terminate: true });\n\t}\n\tif (segments.length === 0) {\n\t\treturn buildToolResult(DECLINE_MESSAGE, { answers: result.answers, cancelled: true });\n\t}\n\treturn buildToolResult(`${ENVELOPE_PREFIX} ${segments.join(\" \")} ${ENVELOPE_SUFFIX}`, result);\n}\n\n/**\n * Format a single answer segment for the envelope. Pure of `a`. The `\"Q\"=\"A\"` shape and\n * the optional `selected preview:` / `user notes:` suffixes are pinned by envelope tests.\n */\nexport function buildAnswerSegment(a: QuestionAnswer): string {\n\tconst parts: string[] = [`\"${a.question}\"=\"${formatAnswerScalar(a, \"envelope\")}\"`];\n\tif (a.preview && a.preview.length > 0) parts.push(`selected preview: ${a.preview}`);\n\tif (a.notes && a.notes.length > 0) parts.push(`user notes: ${a.notes}`);\n\treturn `${parts.join(\". \")}.`;\n}\n\nexport function buildToolResult(text: string, details: QuestionnaireResult, options?: { terminate?: boolean }) {\n\treturn {\n\t\tcontent: [{ type: \"text\" as const, text }],\n\t\tdetails,\n\t\t...(options?.terminate === true ? { terminate: true } : {}),\n\t};\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bastani/atomic",
3
- "version": "0.8.26-alpha.5",
3
+ "version": "0.8.26-alpha.6",
4
4
  "description": "Atomic coding agent CLI with read, bash, edit, write tools and session management",
5
5
  "type": "module",
6
6
  "atomicConfig": {