poe-code 3.0.159 → 3.0.160

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -825,15 +825,25 @@ async function resolve(chain, options) {
825
825
  visited: /* @__PURE__ */ new Set([documentLayer.filePath]),
826
826
  depth: 1
827
827
  }) : void 0;
828
+ const composedPrompt = composePromptChain(
829
+ {
830
+ source: documentLayer.source,
831
+ data: parsedDocument.data
832
+ },
833
+ resolvedBase?.layers ?? []
834
+ );
828
835
  const merged = mergeLayers([
829
836
  ...collectDataLayers(chain.slice(0, documentIndex)),
830
837
  {
831
838
  source: documentLayer.source,
832
- data: parsedDocument.data
839
+ data: withResolvedPrompt(parsedDocument.data, composedPrompt?.prompt)
833
840
  },
834
- ...resolvedBase?.layers ?? [],
841
+ ...stripResolvedBasePrompts(resolvedBase?.layers ?? [], composedPrompt?.consumedBaseIndexes ?? /* @__PURE__ */ new Set()),
835
842
  ...collectDataLayers(chain.slice(documentIndex + 1))
836
843
  ]);
844
+ if (composedPrompt !== void 0 && merged.sources.prompt === documentLayer.source && composedPrompt.source !== void 0) {
845
+ merged.sources.prompt = composedPrompt.source;
846
+ }
837
847
  return {
838
848
  data: merged.data,
839
849
  sources: merged.sources,
@@ -926,6 +936,89 @@ Visited files:
926
936
  function collectDataLayers(chain) {
927
937
  return chain.filter(isDataLayer);
928
938
  }
939
+ function composePromptChain(documentLayer, baseLayers) {
940
+ const documentPrompt = documentLayer.data.prompt;
941
+ if (documentPrompt !== void 0 && typeof documentPrompt !== "string") {
942
+ return void 0;
943
+ }
944
+ if (documentPrompt !== void 0) {
945
+ assertValidYieldCount(documentPrompt);
946
+ }
947
+ let prompt = documentPrompt;
948
+ let source = prompt === void 0 || prompt === "" ? void 0 : documentLayer.source;
949
+ const consumedBaseIndexes = /* @__PURE__ */ new Set();
950
+ for (const [index, layer] of baseLayers.entries()) {
951
+ const candidate = layer.data.prompt;
952
+ if (candidate === void 0) {
953
+ continue;
954
+ }
955
+ if (typeof candidate !== "string") {
956
+ break;
957
+ }
958
+ assertValidYieldCount(candidate);
959
+ consumedBaseIndexes.add(index);
960
+ prompt = composeAdjacentPrompts(prompt, candidate);
961
+ if (source === void 0 && candidate !== "") {
962
+ source = layer.source;
963
+ }
964
+ }
965
+ if (prompt !== void 0 && prompt.includes(YIELD_TOKEN)) {
966
+ throw new Error('Final resolved prompt contains an unresolved "{{yield}}" token.');
967
+ }
968
+ if (prompt === void 0) {
969
+ return void 0;
970
+ }
971
+ return {
972
+ consumedBaseIndexes,
973
+ prompt,
974
+ source
975
+ };
976
+ }
977
+ function composeAdjacentPrompts(high, low) {
978
+ if (high === void 0 || high === "") {
979
+ return low.includes(YIELD_TOKEN) ? replaceYield(low, "") : low;
980
+ }
981
+ if (high.includes(YIELD_TOKEN)) {
982
+ return replaceYield(high, low);
983
+ }
984
+ if (low.includes(YIELD_TOKEN)) {
985
+ return replaceYield(low, high);
986
+ }
987
+ return high;
988
+ }
989
+ function replaceYield(prompt, replacement) {
990
+ return prompt.replace(YIELD_TOKEN, replacement);
991
+ }
992
+ function assertValidYieldCount(prompt) {
993
+ if (countYieldTokens(prompt) > 1) {
994
+ throw new Error('Prompt composition supports exactly one "{{yield}}" token per prompt.');
995
+ }
996
+ }
997
+ function countYieldTokens(prompt) {
998
+ return prompt.split(YIELD_TOKEN).length - 1;
999
+ }
1000
+ function withResolvedPrompt(data, prompt) {
1001
+ if (prompt === void 0) {
1002
+ return data;
1003
+ }
1004
+ return {
1005
+ ...data,
1006
+ prompt
1007
+ };
1008
+ }
1009
+ function stripResolvedBasePrompts(layers, consumedBaseIndexes) {
1010
+ return layers.map((layer, index) => {
1011
+ if (!consumedBaseIndexes.has(index) || typeof layer.data.prompt !== "string") {
1012
+ return layer;
1013
+ }
1014
+ const { prompt: ignoredPrompt, ...data } = layer.data;
1015
+ void ignoredPrompt;
1016
+ return {
1017
+ source: layer.source,
1018
+ data
1019
+ };
1020
+ });
1021
+ }
929
1022
  function getBaseName(filePath) {
930
1023
  return path4.basename(filePath, path4.extname(filePath));
931
1024
  }
@@ -944,7 +1037,7 @@ function isDocumentLayer(layer) {
944
1037
  function isBaseLayer(layer) {
945
1038
  return "path" in layer;
946
1039
  }
947
- var MAX_EXTENDS_DEPTH;
1040
+ var MAX_EXTENDS_DEPTH, YIELD_TOKEN;
948
1041
  var init_resolve = __esm({
949
1042
  "packages/config-extends/src/resolve.ts"() {
950
1043
  "use strict";
@@ -952,6 +1045,7 @@ var init_resolve = __esm({
952
1045
  init_merge();
953
1046
  init_parse();
954
1047
  MAX_EXTENDS_DEPTH = 5;
1048
+ YIELD_TOKEN = "{{yield}}";
955
1049
  }
956
1050
  });
957
1051
 
@@ -19017,9 +19111,10 @@ function buildTemplateContext(env) {
19017
19111
  const repo = getOptionalEnvValue(env, "GITHUB_REPOSITORY");
19018
19112
  const issueNumber = getOptionalEnvValue(env, "ISSUE_NUMBER");
19019
19113
  const prNumber = getOptionalEnvValue(env, "PR_NUMBER");
19114
+ const url = buildUrl(repo, issueNumber, prNumber);
19020
19115
  return {
19021
19116
  ...repo === void 0 ? {} : { repo },
19022
- ...buildUrl(repo, issueNumber, prNumber) === void 0 ? {} : { url: buildUrl(repo, issueNumber, prNumber) },
19117
+ ...url === void 0 ? {} : { url },
19023
19118
  issue: pruneUndefined({
19024
19119
  number: issueNumber,
19025
19120
  title: getOptionalEnvValue(env, "ISSUE_TITLE"),
@@ -19085,12 +19180,7 @@ function buildPerItemTemplateContext(item, sharedContext) {
19085
19180
  };
19086
19181
  }
19087
19182
  function renderPrompt(template, view) {
19088
- Mustache3.escape = (value) => value;
19089
- try {
19090
- return Mustache3.render(template, view);
19091
- } finally {
19092
- Mustache3.escape = originalMustacheEscape;
19093
- }
19183
+ return Mustache3.render(template, view);
19094
19184
  }
19095
19185
  function resolveSourceCommand(source, env) {
19096
19186
  const repo = env.get("GITHUB_REPOSITORY");
@@ -19225,7 +19315,7 @@ async function selectAutomationName(message2, automations) {
19225
19315
  }
19226
19316
  return selected;
19227
19317
  }
19228
- var UPSTREAM_REPO, builtInPromptsDirCandidates, builtInWorkflowTemplatesDirCandidates, originalMustacheEscape, installableAutomations, runCommandDef, listCommand, installCommand, uninstallCommand, requireUserAllowCommand, requireCommentPrefixCommand, prepareCommand, promptPreviewCommand, variablesCommand, ghGroup;
19318
+ var UPSTREAM_REPO, builtInPromptsDirCandidates, builtInWorkflowTemplatesDirCandidates, installableAutomations, runCommandDef, listCommand, installCommand, uninstallCommand, requireUserAllowCommand, requireCommentPrefixCommand, prepareCommand, promptPreviewCommand, variablesCommand, ghGroup;
19229
19319
  var init_commands = __esm({
19230
19320
  "packages/github-workflows/src/commands.ts"() {
19231
19321
  "use strict";
@@ -19248,7 +19338,7 @@ var init_commands = __esm({
19248
19338
  fileURLToPath4(new URL("./workflow-templates", import.meta.url)),
19249
19339
  fileURLToPath4(new URL("../src/workflow-templates", import.meta.url))
19250
19340
  ];
19251
- originalMustacheEscape = Mustache3.escape;
19341
+ Mustache3.escape = (value) => value;
19252
19342
  installableAutomations = [
19253
19343
  "fix-vulnerabilities",
19254
19344
  "github-issue-comment-created",
@@ -33374,7 +33464,7 @@ var init_package = __esm({
33374
33464
  "package.json"() {
33375
33465
  package_default = {
33376
33466
  name: "poe-code",
33377
- version: "3.0.159",
33467
+ version: "3.0.160",
33378
33468
  description: "CLI tool to configure Poe API for developer workflows.",
33379
33469
  type: "module",
33380
33470
  main: "./dist/index.js",