@vedangiitb/qwintly-core 1.3.7 → 1.3.9
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/ai/prompts/codegen.prompt.d.ts.map +1 -1
- package/dist/ai/prompts/codegen.prompt.js +37 -39
- package/dist/ai/prompts/codegen.prompt.js.map +1 -1
- package/dist/ai/prompts/examples/codegen.examples.js +1 -1
- package/dist/ai/prompts/examples/codegen.examples.js.map +1 -1
- package/dist/ai/prompts/examples/planner.examples.d.ts.map +1 -1
- package/dist/ai/prompts/examples/planner.examples.js +6 -1
- package/dist/ai/prompts/examples/planner.examples.js.map +1 -1
- package/dist/ai/prompts/helpers/promptParts.helper.d.ts +1 -3
- package/dist/ai/prompts/helpers/promptParts.helper.d.ts.map +1 -1
- package/dist/ai/prompts/helpers/promptParts.helper.js +9 -18
- package/dist/ai/prompts/helpers/promptParts.helper.js.map +1 -1
- package/dist/ai/prompts/planner.prompt.d.ts.map +1 -1
- package/dist/ai/prompts/planner.prompt.js +32 -36
- package/dist/ai/prompts/planner.prompt.js.map +1 -1
- package/dist/ai/prompts/validator.prompt.d.ts.map +1 -1
- package/dist/ai/prompts/validator.prompt.js +38 -39
- package/dist/ai/prompts/validator.prompt.js.map +1 -1
- package/dist/ai/toolLoop/toolLoopContext.js +1 -1
- package/dist/ai/toolLoop/toolLoopContext.js.map +1 -1
- package/dist/ai/toolLoop/toolLoopRunner.d.ts.map +1 -1
- package/dist/ai/toolLoop/toolLoopRunner.js +22 -15
- package/dist/ai/toolLoop/toolLoopRunner.js.map +1 -1
- package/dist/ai/toolLoop/toolLoopRunnerUtils.d.ts.map +1 -1
- package/dist/ai/toolLoop/toolLoopRunnerUtils.js +13 -0
- package/dist/ai/toolLoop/toolLoopRunnerUtils.js.map +1 -1
- package/dist/ai/tools/implementations/createNewRoute.impl.d.ts +13 -1
- package/dist/ai/tools/implementations/createNewRoute.impl.d.ts.map +1 -1
- package/dist/ai/tools/implementations/createNewRoute.impl.js +98 -29
- package/dist/ai/tools/implementations/createNewRoute.impl.js.map +1 -1
- package/dist/ai/tools/implementations/factories.d.ts +17 -2
- package/dist/ai/tools/implementations/factories.d.ts.map +1 -1
- package/dist/ai/tools/implementations/insertElement.impl.d.ts.map +1 -1
- package/dist/ai/tools/implementations/insertElement.impl.js +1 -1
- package/dist/ai/tools/implementations/insertElement.impl.js.map +1 -1
- package/dist/ai/tools/implementations/readFile.impl.d.ts +4 -1
- package/dist/ai/tools/implementations/readFile.impl.d.ts.map +1 -1
- package/dist/ai/tools/implementations/readFile.impl.js +10 -0
- package/dist/ai/tools/implementations/readFile.impl.js.map +1 -1
- package/dist/ai/tools/schemas/createNewRoute.schema.js +1 -1
- package/dist/ai/tools/schemas/createNewRoute.schema.js.map +1 -1
- package/dist/ai/tools/schemas/insertElement.schema.d.ts.map +1 -1
- package/dist/ai/tools/schemas/insertElement.schema.js +7 -7
- package/dist/ai/tools/schemas/insertElement.schema.js.map +1 -1
- package/dist/ai/tools/schemas/updateProps.schema.js +1 -1
- package/dist/ai/tools/schemas/updateProps.schema.js.map +1 -1
- package/dist/image/unsplash.service.d.ts.map +1 -1
- package/dist/image/unsplash.service.js +1 -0
- package/dist/image/unsplash.service.js.map +1 -1
- package/dist/indexer/data/configs.constants.d.ts +21 -28
- package/dist/indexer/data/configs.constants.d.ts.map +1 -1
- package/dist/indexer/data/configs.constants.js +34 -45
- package/dist/indexer/data/configs.constants.js.map +1 -1
- package/dist/tests/createNewRoute.impl.test.js +11 -3
- package/dist/tests/createNewRoute.impl.test.js.map +1 -1
- package/dist/types/public.d.ts +0 -1
- package/dist/types/public.d.ts.map +1 -1
- package/dist/types/public.js.map +1 -1
- package/package.json +1 -1
- package/dist/types/index/conventions.types.d.ts +0 -40
- package/dist/types/index/conventions.types.d.ts.map +0 -1
- package/dist/types/index/conventions.types.js +0 -2
- package/dist/types/index/conventions.types.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codegen.prompt.d.ts","sourceRoot":"","sources":["../../../src/ai/prompts/codegen.prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,gBAAgB,
|
|
1
|
+
{"version":3,"file":"codegen.prompt.d.ts","sourceRoot":"","sources":["../../../src/ai/prompts/codegen.prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAQvE,MAAM,MAAM,uBAAuB,GAAG;IACpC,IAAI,EAAE,GAAG,CAAC;IACV,YAAY,EAAE,YAAY,CAAC;IAC3B,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,YAAY,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,QAAQ,uBAAuB,WAoE5D,CAAC"}
|
|
@@ -2,51 +2,49 @@ import { codegenExamples } from "./examples/codegen.examples.js";
|
|
|
2
2
|
import { jsonBlock, mdSection, projectStateNote, } from "./helpers/promptParts.helper.js";
|
|
3
3
|
export const codegenPrompt = (params) => {
|
|
4
4
|
const { task, codegenIndex, collectedContext, isNewProject } = params;
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
`;
|
|
8
|
-
const context = mdSection("Context (Authoritative)", [
|
|
9
|
-
jsonBlock("Project Context (User preferences etc.)", collectedContext ?? {}),
|
|
10
|
-
].join("\n"));
|
|
11
|
-
const projectConfiguration = mdSection("Project Configuration", [
|
|
12
|
-
jsonBlock("FRAMEWORK CONFIG", codegenIndex.projectConfigs.frameworkConfig),
|
|
13
|
-
jsonBlock("RUNTIME CONFIG", codegenIndex.projectConfigs.runtimeConfig),
|
|
14
|
-
jsonBlock("RENDERING CONFIGURATION", codegenIndex.projectConfigs.renderingConfig),
|
|
15
|
-
].join("\n"));
|
|
16
|
-
const toolsInfo = mdSection("Tool Usage", `
|
|
17
|
-
You are provided access to the following tools and use them to implement coding tasks.
|
|
18
|
-
|
|
19
|
-
read_file: Use when you want to read a file from the codebase.
|
|
5
|
+
const system = `
|
|
6
|
+
You are a senior software engineer implementing tasks in an existing codebase.
|
|
20
7
|
|
|
21
|
-
|
|
8
|
+
Rules:
|
|
9
|
+
- Implement ONLY the requested task.
|
|
10
|
+
- Prefer incremental edits over rewrites.
|
|
11
|
+
- Be concise and deterministic.
|
|
12
|
+
- Do not output code directly; use tools.
|
|
22
13
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
14
|
+
${projectStateNote(isNewProject, "codegen")}
|
|
15
|
+
`.trim();
|
|
16
|
+
const taskInfo = mdSection("Task to implement", jsonBlock("task", task ?? null));
|
|
17
|
+
const toolsInfo = mdSection("Tools", `
|
|
18
|
+
Available tools:
|
|
28
19
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
20
|
+
- read_file: Read file
|
|
21
|
+
- list_dir: List directory
|
|
22
|
+
- create_new_route: Create route with page.tsx + pageConfig.json
|
|
23
|
+
- insert_element: Insert element tree
|
|
24
|
+
- delete_element: Delete element
|
|
25
|
+
- update_classname: Update className
|
|
26
|
+
- update_props: Update props
|
|
27
|
+
- submit_codegen_done: Finish task
|
|
32
28
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
29
|
+
Rules:
|
|
30
|
+
- One insert_element per tree (include children inline) unless depth blocks it.
|
|
31
|
+
- Create missing routes with create_new_route.
|
|
32
|
+
- image src auto-generated from alt
|
|
33
|
+
- lucide-react icons only
|
|
34
|
+
`.trim());
|
|
35
|
+
const projectConfiguration = mdSection("Project Config", [
|
|
36
|
+
jsonBlock("framework", codegenIndex.projectConfigs.frameworkConfig),
|
|
37
|
+
jsonBlock("runtime", codegenIndex.projectConfigs.runtimeConfig),
|
|
38
|
+
jsonBlock("rendering", codegenIndex.projectConfigs.renderingConfig),
|
|
39
|
+
].join("\n"));
|
|
40
|
+
const context = mdSection("Relevant Context", jsonBlock("context", collectedContext ?? {}));
|
|
43
41
|
const sections = [
|
|
44
|
-
|
|
45
|
-
context,
|
|
46
|
-
projectConfiguration,
|
|
47
|
-
toolsInfo,
|
|
48
|
-
examples,
|
|
42
|
+
system,
|
|
49
43
|
taskInfo,
|
|
44
|
+
toolsInfo,
|
|
45
|
+
projectConfiguration,
|
|
46
|
+
context,
|
|
47
|
+
codegenExamples,
|
|
50
48
|
];
|
|
51
49
|
return sections.join("\n\n---\n\n");
|
|
52
50
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codegen.prompt.js","sourceRoot":"","sources":["../../../src/ai/prompts/codegen.prompt.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EACL,SAAS,EACT,SAAS,EACT,gBAAgB,GACjB,MAAM,iCAAiC,CAAC;AASzC,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,MAA+B,EAAE,EAAE;IAC/D,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,gBAAgB,EAAE,YAAY,EAAE,GAAG,MAAM,CAAC;IAEtE,MAAM,
|
|
1
|
+
{"version":3,"file":"codegen.prompt.js","sourceRoot":"","sources":["../../../src/ai/prompts/codegen.prompt.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EACL,SAAS,EACT,SAAS,EACT,gBAAgB,GACjB,MAAM,iCAAiC,CAAC;AASzC,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,MAA+B,EAAE,EAAE;IAC/D,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,gBAAgB,EAAE,YAAY,EAAE,GAAG,MAAM,CAAC;IAEtE,MAAM,MAAM,GAAG;;;;;;;;;MASX,gBAAgB,CAAC,YAAY,EAAE,SAAS,CAAC;GAC5C,CAAC,IAAI,EAAE,CAAC;IAET,MAAM,QAAQ,GAAG,SAAS,CACxB,mBAAmB,EACnB,SAAS,CAAC,MAAM,EAAE,IAAI,IAAI,IAAI,CAAC,CAChC,CAAC;IAEF,MAAM,SAAS,GAAG,SAAS,CACzB,OAAO,EACP;;;;;;;;;;;;;;;;;KAiBC,CAAC,IAAI,EAAE,CACT,CAAC;IAEF,MAAM,oBAAoB,GAAG,SAAS,CACpC,gBAAgB,EAChB;QACE,SAAS,CAAC,WAAW,EAAE,YAAY,CAAC,cAAc,CAAC,eAAe,CAAC;QAEnE,SAAS,CAAC,SAAS,EAAE,YAAY,CAAC,cAAc,CAAC,aAAa,CAAC;QAE/D,SAAS,CAAC,WAAW,EAAE,YAAY,CAAC,cAAc,CAAC,eAAe,CAAC;KACpE,CAAC,IAAI,CAAC,IAAI,CAAC,CACb,CAAC;IAEF,MAAM,OAAO,GAAG,SAAS,CACvB,kBAAkB,EAClB,SAAS,CAAC,SAAS,EAAE,gBAAgB,IAAI,EAAE,CAAC,CAC7C,CAAC;IAEF,MAAM,QAAQ,GAAG;QACf,MAAM;QACN,QAAQ;QACR,SAAS;QACT,oBAAoB;QACpB,OAAO;QACP,eAAe;KAChB,CAAC;IAEF,OAAO,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;AACtC,CAAC,CAAC","sourcesContent":["import { CodegenIndex, CollectedContext } from \"../../types/public.js\";\r\nimport { codegenExamples } from \"./examples/codegen.examples.js\";\r\nimport {\r\n jsonBlock,\r\n mdSection,\r\n projectStateNote,\r\n} from \"./helpers/promptParts.helper.js\";\r\n\r\nexport type CodegenNodePromptParams = {\r\n task: any;\r\n codegenIndex: CodegenIndex;\r\n collectedContext: CollectedContext;\r\n isNewProject: boolean;\r\n};\r\n\r\nexport const codegenPrompt = (params: CodegenNodePromptParams) => {\r\n const { task, codegenIndex, collectedContext, isNewProject } = params;\r\n\r\n const system = `\r\n You are a senior software engineer implementing tasks in an existing codebase.\r\n\r\n Rules:\r\n - Implement ONLY the requested task.\r\n - Prefer incremental edits over rewrites.\r\n - Be concise and deterministic.\r\n - Do not output code directly; use tools.\r\n\r\n ${projectStateNote(isNewProject, \"codegen\")}\r\n `.trim();\r\n\r\n const taskInfo = mdSection(\r\n \"Task to implement\",\r\n jsonBlock(\"task\", task ?? null),\r\n );\r\n\r\n const toolsInfo = mdSection(\r\n \"Tools\",\r\n `\r\n Available tools:\r\n\r\n - read_file: Read file\r\n - list_dir: List directory\r\n - create_new_route: Create route with page.tsx + pageConfig.json\r\n - insert_element: Insert element tree\r\n - delete_element: Delete element\r\n - update_classname: Update className\r\n - update_props: Update props\r\n - submit_codegen_done: Finish task\r\n\r\n Rules:\r\n - One insert_element per tree (include children inline) unless depth blocks it.\r\n - Create missing routes with create_new_route.\r\n - image src auto-generated from alt\r\n - lucide-react icons only\r\n `.trim(),\r\n );\r\n\r\n const projectConfiguration = mdSection(\r\n \"Project Config\",\r\n [\r\n jsonBlock(\"framework\", codegenIndex.projectConfigs.frameworkConfig),\r\n\r\n jsonBlock(\"runtime\", codegenIndex.projectConfigs.runtimeConfig),\r\n\r\n jsonBlock(\"rendering\", codegenIndex.projectConfigs.renderingConfig),\r\n ].join(\"\\n\"),\r\n );\r\n\r\n const context = mdSection(\r\n \"Relevant Context\",\r\n jsonBlock(\"context\", collectedContext ?? {}),\r\n );\r\n\r\n const sections = [\r\n system,\r\n taskInfo,\r\n toolsInfo,\r\n projectConfiguration,\r\n context,\r\n codegenExamples,\r\n ];\r\n\r\n return sections.join(\"\\n\\n---\\n\\n\");\r\n};\r\n"]}
|
|
@@ -55,7 +55,7 @@ Notes:
|
|
|
55
55
|
`### Example: \`update_props\` (update element props)
|
|
56
56
|
Goal: Update the text and click action for a button.
|
|
57
57
|
|
|
58
|
-
Tool call (function name in tool schema is \`
|
|
58
|
+
Tool call (function name in tool schema is \`update_props\`):
|
|
59
59
|
\`\`\`json
|
|
60
60
|
{
|
|
61
61
|
"route": "/",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codegen.examples.js","sourceRoot":"","sources":["../../../../src/ai/prompts/examples/codegen.examples.ts"],"names":[],"mappings":"AAAA,MAAM,QAAQ,GAAG;IACf;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0DAsCwD;IAExD;;;;;;;;;;;;;+DAa6D;IAE7D;;;;;;;;;;;;;;;;;;;;;;;;8FAwB4F;CAC7F,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC","sourcesContent":["const examples = [\n `## Examples of tool calls\n\n### Example: \\`insert_element\\` (add a CTA section)\nGoal: Insert a new section under the page root on route \\`/\\`.\n\nTool call:\n\\`\\`\\`json\n{\n \"route\": \"/\",\n \"parent_id\": \"root\",\n \"element\": {\n \"type\": \"div\",\n \"className\": \"mt-10 flex items-center justify-between gap-6 rounded-2xl border border-slate-200 bg-white p-6\",\n \"children\": [\n {\n \"type\": \"div\",\n \"className\": \"flex flex-col gap-1\",\n \"children\": [\n { \"type\": \"text\", \"className\": \"text-lg font-semibold text-slate-900\", \"props\": { \"text\": \"Ready to get started?\" } },\n { \"type\": \"text\", \"className\": \"text-sm text-slate-600\", \"props\": { \"text\": \"Create your first project in under a minute.\" } }\n ]\n },\n {\n \"type\": \"button\",\n \"className\": \"inline-flex items-center justify-center rounded-xl bg-slate-900 px-4 py-2 text-sm font-medium text-white hover:bg-slate-800\",\n \"props\": {\n \"text\": \"Get Started\",\n \"onClick\": { \"kind\": \"route\", \"href\": \"/signup\" }\n }\n }\n ]\n }\n}\n\\`\\`\\`\n\nNotes:\n- Always pass a complete \\`className\\` string (Tailwind only).\n- Use \\`children\\` to nest elements; children can themselves have \\`children\\` (deep nesting is supported).\n- Use the returned \\`inserted_id\\` for follow-up updates.`,\n\n `### Example: \\`update_classname\\` (replace className fully)\nGoal: Update styling on an existing element.\n\nTool call:\n\\`\\`\\`json\n{\n \"route\": \"/\",\n \"element_id\": \"el_123abc\",\n \"className\": \"mt-8 grid grid-cols-1 gap-6 sm:grid-cols-2 lg:grid-cols-3\"\n}\n\\`\\`\\`\n\nNotes:\n- Provide the full \\`className\\`; do not send partial patches.`,\n\n `### Example: \\`update_props\\` (update element props)\nGoal: Update the text and click action for a button.\n\nTool call (function name in tool schema is \\`
|
|
1
|
+
{"version":3,"file":"codegen.examples.js","sourceRoot":"","sources":["../../../../src/ai/prompts/examples/codegen.examples.ts"],"names":[],"mappings":"AAAA,MAAM,QAAQ,GAAG;IACf;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0DAsCwD;IAExD;;;;;;;;;;;;;+DAa6D;IAE7D;;;;;;;;;;;;;;;;;;;;;;;;8FAwB4F;CAC7F,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC","sourcesContent":["const examples = [\n `## Examples of tool calls\n\n### Example: \\`insert_element\\` (add a CTA section)\nGoal: Insert a new section under the page root on route \\`/\\`.\n\nTool call:\n\\`\\`\\`json\n{\n \"route\": \"/\",\n \"parent_id\": \"root\",\n \"element\": {\n \"type\": \"div\",\n \"className\": \"mt-10 flex items-center justify-between gap-6 rounded-2xl border border-slate-200 bg-white p-6\",\n \"children\": [\n {\n \"type\": \"div\",\n \"className\": \"flex flex-col gap-1\",\n \"children\": [\n { \"type\": \"text\", \"className\": \"text-lg font-semibold text-slate-900\", \"props\": { \"text\": \"Ready to get started?\" } },\n { \"type\": \"text\", \"className\": \"text-sm text-slate-600\", \"props\": { \"text\": \"Create your first project in under a minute.\" } }\n ]\n },\n {\n \"type\": \"button\",\n \"className\": \"inline-flex items-center justify-center rounded-xl bg-slate-900 px-4 py-2 text-sm font-medium text-white hover:bg-slate-800\",\n \"props\": {\n \"text\": \"Get Started\",\n \"onClick\": { \"kind\": \"route\", \"href\": \"/signup\" }\n }\n }\n ]\n }\n}\n\\`\\`\\`\n\nNotes:\n- Always pass a complete \\`className\\` string (Tailwind only).\n- Use \\`children\\` to nest elements; children can themselves have \\`children\\` (deep nesting is supported).\n- Use the returned \\`inserted_id\\` for follow-up updates.`,\n\n `### Example: \\`update_classname\\` (replace className fully)\nGoal: Update styling on an existing element.\n\nTool call:\n\\`\\`\\`json\n{\n \"route\": \"/\",\n \"element_id\": \"el_123abc\",\n \"className\": \"mt-8 grid grid-cols-1 gap-6 sm:grid-cols-2 lg:grid-cols-3\"\n}\n\\`\\`\\`\n\nNotes:\n- Provide the full \\`className\\`; do not send partial patches.`,\n\n `### Example: \\`update_props\\` (update element props)\nGoal: Update the text and click action for a button.\n\nTool call (function name in tool schema is \\`update_props\\`):\n\\`\\`\\`json\n{\n \"route\": \"/\",\n \"element_id\": \"el_123abc\",\n \"text\": \"Start free trial\",\n \"onClick\": { \"kind\": \"route\", \"href\": \"/pricing\", \"replace\": false }\n}\n\\`\\`\\`\n\nOther common prop updates:\n\\`\\`\\`json\n{\n \"route\": \"/\",\n \"element_id\": \"el_img_001\",\n \"alt\": \"A person collaborating on a laptop in a bright office\"\n}\n\\`\\`\\`\n\nNotes:\n- Only include props you want to change; omitted fields remain unchanged.\n- For images, \\`alt\\` is also used to fetch a suitable Unsplash image (src is auto-resolved).`,\n];\n\nexport const codegenExamples = examples.join(\"\\n\");\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"planner.examples.d.ts","sourceRoot":"","sources":["../../../../src/ai/prompts/examples/planner.examples.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"planner.examples.d.ts","sourceRoot":"","sources":["../../../../src/ai/prompts/examples/planner.examples.ts"],"names":[],"mappings":"AAqCA,eAAO,MAAM,eAAe,QAAsB,CAAC"}
|
|
@@ -13,12 +13,16 @@ Tool call:
|
|
|
13
13
|
"targets": ["app/pricing/page.tsx", "app/pricing/pageConfig.json"]
|
|
14
14
|
},
|
|
15
15
|
{
|
|
16
|
-
"description": "Update app/pricing/pageConfig.json to add a hero section with a title, subtitle, and two buttons (Primary: 'Start free trial' routes to /signup, Secondary: 'View docs' opens an external link in a new tab). Ensure all elements have ids and use Tailwind className strings only.",
|
|
16
|
+
"description": "Update app/pricing/pageConfig.json to add a hero section with a title, subtitle, and two buttons (Primary: 'Start free trial' routes to /signup, Secondary: 'View docs' opens an external link in a new tab). Add a hero image, a person sitting on a laptop in a bright office, and a quote. Ensure all elements have ids and use Tailwind className strings only.",
|
|
17
17
|
"targets": ["app/pricing/pageConfig.json"]
|
|
18
18
|
},
|
|
19
19
|
{
|
|
20
20
|
"description": "Add a 3-tier pricing cards section (Starter/Pro/Enterprise) in app/pricing/pageConfig.json with consistent spacing, responsive layout, and clear feature bullet lists. Use lucide-react icons for checkmarks and keep the JSON tree minimal and readable.",
|
|
21
21
|
"targets": ["app/pricing/pageConfig.json"]
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"description": "Create an items section for cakes. Include images of cakes",
|
|
25
|
+
"targets": ["app/items/pageConfig.json"]
|
|
22
26
|
}
|
|
23
27
|
]
|
|
24
28
|
}
|
|
@@ -26,6 +30,7 @@ Tool call:
|
|
|
26
30
|
|
|
27
31
|
Notes:
|
|
28
32
|
- Each task must be atomic and ordered.
|
|
33
|
+
- You can ask to include images whereever needed in the task description. Also tell what the image should be.
|
|
29
34
|
- \`description\` must NOT include code blocks; reference exact paths and expected end state.
|
|
30
35
|
- \`targets\` must be workspace-relative paths that will be modified or referenced.`,
|
|
31
36
|
];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"planner.examples.js","sourceRoot":"","sources":["../../../../src/ai/prompts/examples/planner.examples.ts"],"names":[],"mappings":"AAAA,MAAM,QAAQ,GAAG;IACf
|
|
1
|
+
{"version":3,"file":"planner.examples.js","sourceRoot":"","sources":["../../../../src/ai/prompts/examples/planner.examples.ts"],"names":[],"mappings":"AAAA,MAAM,QAAQ,GAAG;IACf;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oFAiCkF;CACnF,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC","sourcesContent":["const examples = [\n `## Examples\n\n### Example: \\`submit_planner_tasks\\` (final response format)\nGoal: Return an ordered, atomic task list for the codegen agent.\n\nTool call:\n\\`\\`\\`json\n{\n \"planner_tasks\": [\n {\n \"description\": \"Create the /pricing route using create_new_route if it does not exist, and ensure app/pricing/page.tsx imports and renders the pageConfig.json elements via the standard renderer pattern used in this repo.\",\n \"targets\": [\"app/pricing/page.tsx\", \"app/pricing/pageConfig.json\"]\n },\n {\n \"description\": \"Update app/pricing/pageConfig.json to add a hero section with a title, subtitle, and two buttons (Primary: 'Start free trial' routes to /signup, Secondary: 'View docs' opens an external link in a new tab). Add a hero image, a person sitting on a laptop in a bright office, and a quote. Ensure all elements have ids and use Tailwind className strings only.\",\n \"targets\": [\"app/pricing/pageConfig.json\"]\n },\n {\n \"description\": \"Add a 3-tier pricing cards section (Starter/Pro/Enterprise) in app/pricing/pageConfig.json with consistent spacing, responsive layout, and clear feature bullet lists. Use lucide-react icons for checkmarks and keep the JSON tree minimal and readable.\",\n \"targets\": [\"app/pricing/pageConfig.json\"]\n },\n {\n \"description\": \"Create an items section for cakes. Include images of cakes\",\n \"targets\": [\"app/items/pageConfig.json\"]\n }\n ]\n}\n\\`\\`\\`\n\nNotes:\n- Each task must be atomic and ordered.\n- You can ask to include images whereever needed in the task description. Also tell what the image should be.\n- \\`description\\` must NOT include code blocks; reference exact paths and expected end state.\n- \\`targets\\` must be workspace-relative paths that will be modified or referenced.`,\n];\n\nexport const plannerExamples = examples.join(\"\\n\");\n"]}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
export type PromptRole = "planner" | "codegen" | "validator";
|
|
2
|
-
export declare const mdDivider: () => string;
|
|
3
2
|
export declare const mdSection: (title: string, body: string) => string;
|
|
4
3
|
export declare const jsonBlock: (label: string, value: unknown) => string;
|
|
5
|
-
export declare const projectStateNote: (isNewProject: boolean, role: PromptRole) => "The project you are given is currently a boilerplate project that contains some existing code. Create tasks to modify
|
|
4
|
+
export declare const projectStateNote: (isNewProject: boolean, role: PromptRole) => "The project you are given is currently a boilerplate project that contains some existing code. Create tasks to modify project according to PM plan and context; remove boilerplate traces." | "Plan only latest PM changes; avoid rework" | "The project is currently a boilerplate. Implement task cleanly while removing boilerplate patterns." | "Implement task incrementally without breaking existing architecture.";
|
|
6
5
|
export declare const renderPlannerTaskFormatSection: () => string;
|
|
7
|
-
export declare const plannerObjectives: (target: PromptRole) => string;
|
|
8
6
|
//# sourceMappingURL=promptParts.helper.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promptParts.helper.d.ts","sourceRoot":"","sources":["../../../../src/ai/prompts/helpers/promptParts.helper.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,SAAS,GAAG,WAAW,CAAC;AAE7D,eAAO,MAAM,SAAS,
|
|
1
|
+
{"version":3,"file":"promptParts.helper.d.ts","sourceRoot":"","sources":["../../../../src/ai/prompts/helpers/promptParts.helper.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,SAAS,GAAG,WAAW,CAAC;AAE7D,eAAO,MAAM,SAAS,GAAI,OAAO,MAAM,EAAE,MAAM,MAAM,WAGpD,CAAC;AAEF,eAAO,MAAM,SAAS,GAAI,OAAO,MAAM,EAAE,OAAO,OAAO,WACR,CAAC;AAEhD,eAAO,MAAM,gBAAgB,GAAI,cAAc,OAAO,EAAE,MAAM,UAAU,gaAUvE,CAAC;AAEF,eAAO,MAAM,8BAA8B,cAexC,CAAC"}
|
|
@@ -1,37 +1,28 @@
|
|
|
1
|
-
export const mdDivider = () => `\n---\n`;
|
|
2
1
|
export const mdSection = (title, body) => {
|
|
3
2
|
const trimmed = body.trim();
|
|
4
|
-
return
|
|
3
|
+
return `<${title}>${trimmed}</${title}>`;
|
|
5
4
|
};
|
|
6
|
-
export const jsonBlock = (label, value) => `${label}
|
|
5
|
+
export const jsonBlock = (label, value) => `${label}:${JSON.stringify(value ?? null)}\n`;
|
|
7
6
|
export const projectStateNote = (isNewProject, role) => {
|
|
8
7
|
if (role === "planner") {
|
|
9
8
|
return isNewProject
|
|
10
|
-
? "The project you are given is currently a boilerplate project that contains some existing code. Create tasks to modify
|
|
11
|
-
: "
|
|
9
|
+
? "The project you are given is currently a boilerplate project that contains some existing code. Create tasks to modify project according to PM plan and context; remove boilerplate traces."
|
|
10
|
+
: "Plan only latest PM changes; avoid rework";
|
|
12
11
|
}
|
|
13
12
|
return isNewProject
|
|
14
|
-
? "The project is currently a boilerplate. Implement
|
|
15
|
-
: "
|
|
13
|
+
? "The project is currently a boilerplate. Implement task cleanly while removing boilerplate patterns."
|
|
14
|
+
: "Implement task incrementally without breaking existing architecture.";
|
|
16
15
|
};
|
|
17
16
|
export const renderPlannerTaskFormatSection = () => mdSection("Task Format (STRICT)", `
|
|
18
|
-
|
|
17
|
+
After planning, Call submit_planner_tasks with:
|
|
19
18
|
|
|
20
19
|
{
|
|
21
20
|
"planner_tasks": [
|
|
22
21
|
{
|
|
23
|
-
"description": "
|
|
24
|
-
"targets": ["Paths that
|
|
22
|
+
"description": "Exact changes + paths. No code",
|
|
23
|
+
"targets": ["Paths that to be modified or referenced"]
|
|
25
24
|
}
|
|
26
25
|
]
|
|
27
26
|
}
|
|
28
27
|
`.trim());
|
|
29
|
-
export const plannerObjectives = (target) => mdSection("Objectives", `
|
|
30
|
-
1) Create atomic, deterministic tasks to ${target == "validator" ? "resolve ALL validation errors" : "implement PM Plan"} which should include exact file paths to create/modify
|
|
31
|
-
2) Ensure instructions are foolproof for code-gen execution.
|
|
32
|
-
3) Use incremental updates; minimize full rewrites.
|
|
33
|
-
4) Use existing code context wherever possible.
|
|
34
|
-
5) Be token-efficient: concise but technically complete.
|
|
35
|
-
6) DO NOT write code, you have to just plan the tasks
|
|
36
|
-
`.trim());
|
|
37
28
|
//# sourceMappingURL=promptParts.helper.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promptParts.helper.js","sourceRoot":"","sources":["../../../../src/ai/prompts/helpers/promptParts.helper.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,SAAS,GAAG,
|
|
1
|
+
{"version":3,"file":"promptParts.helper.js","sourceRoot":"","sources":["../../../../src/ai/prompts/helpers/promptParts.helper.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,KAAa,EAAE,IAAY,EAAE,EAAE;IACvD,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;IAC5B,OAAO,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,GAAG,CAAC;AAC3C,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,KAAa,EAAE,KAAc,EAAE,EAAE,CACzD,GAAG,KAAK,IAAI,IAAI,CAAC,SAAS,CAAC,KAAK,IAAI,IAAI,CAAC,IAAI,CAAC;AAEhD,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,YAAqB,EAAE,IAAgB,EAAE,EAAE;IAC1E,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,OAAO,YAAY;YACjB,CAAC,CAAC,4LAA4L;YAC9L,CAAC,CAAC,2CAA2C,CAAC;IAClD,CAAC;IAED,OAAO,YAAY;QACjB,CAAC,CAAC,qGAAqG;QACvG,CAAC,CAAC,sEAAsE,CAAC;AAC7E,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,8BAA8B,GAAG,GAAG,EAAE,CACjD,SAAS,CACP,sBAAsB,EACtB;;;;;;;;;;;KAWC,CAAC,IAAI,EAAE,CACT,CAAC","sourcesContent":["export type PromptRole = \"planner\" | \"codegen\" | \"validator\";\n\nexport const mdSection = (title: string, body: string) => {\n const trimmed = body.trim();\n return `<${title}>${trimmed}</${title}>`;\n};\n\nexport const jsonBlock = (label: string, value: unknown) =>\n `${label}:${JSON.stringify(value ?? null)}\\n`;\n\nexport const projectStateNote = (isNewProject: boolean, role: PromptRole) => {\n if (role === \"planner\") {\n return isNewProject\n ? \"The project you are given is currently a boilerplate project that contains some existing code. Create tasks to modify project according to PM plan and context; remove boilerplate traces.\"\n : \"Plan only latest PM changes; avoid rework\";\n }\n\n return isNewProject\n ? \"The project is currently a boilerplate. Implement task cleanly while removing boilerplate patterns.\"\n : \"Implement task incrementally without breaking existing architecture.\";\n};\n\nexport const renderPlannerTaskFormatSection = () =>\n mdSection(\n \"Task Format (STRICT)\",\n `\nAfter planning, Call submit_planner_tasks with:\n\n{\n \"planner_tasks\": [\n {\n \"description\": \"Exact changes + paths. No code\",\n \"targets\": [\"Paths that to be modified or referenced\"]\n }\n ]\n}\n `.trim(),\n );\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"planner.prompt.d.ts","sourceRoot":"","sources":["../../../src/ai/prompts/planner.prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"planner.prompt.d.ts","sourceRoot":"","sources":["../../../src/ai/prompts/planner.prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AASrD,MAAM,MAAM,oBAAoB,GAAG;IACjC,SAAS,EAAE,OAAO,EAAE,CAAC;IACrB,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,YAAY,EAAE,YAAY,CAAC;IAC3B,YAAY,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,QAAQ,oBAAoB,WA+DzD,CAAC"}
|
|
@@ -1,48 +1,44 @@
|
|
|
1
1
|
import { plannerExamples } from "./examples/planner.examples.js";
|
|
2
|
-
import { jsonBlock, mdSection,
|
|
2
|
+
import { jsonBlock, mdSection, projectStateNote, renderPlannerTaskFormatSection, } from "./helpers/promptParts.helper.js";
|
|
3
3
|
export const plannerPrompt = (params) => {
|
|
4
4
|
const { planTasks, collectedContext, plannerIndex, isNewProject } = params;
|
|
5
|
-
const
|
|
6
|
-
You are a senior software architect.
|
|
7
|
-
Based on the provided PM plan and code context, generate a detailed technical implementation plan.
|
|
8
|
-
Provide precise, step-by-step instructions for a code-generation agent; ensure tasks are explicit, atomic, and ordered.
|
|
9
|
-
${projectStateNote(isNewProject, "planner")}
|
|
10
|
-
`.trim();
|
|
11
|
-
const objectives = plannerObjectives("planner");
|
|
12
|
-
const context = mdSection("Inputs (Authoritative)", [
|
|
13
|
-
jsonBlock("Project Context (User preferences etc.)", collectedContext ?? {}),
|
|
14
|
-
].join("\n"));
|
|
15
|
-
const projectConfiguration = mdSection("Project Configuration", [
|
|
16
|
-
jsonBlock("FRAMEWORK CONFIG", plannerIndex.projectConfigs.frameworkConfig),
|
|
17
|
-
jsonBlock("RUNTIME CONFIG", plannerIndex.projectConfigs.runtimeConfig),
|
|
18
|
-
jsonBlock("TOOLING CONFIG", plannerIndex.projectConfigs.toolingConfig),
|
|
19
|
-
jsonBlock("RENDERING CONFIGURATION", plannerIndex.projectConfigs.renderingConfig),
|
|
20
|
-
].join("\n"));
|
|
21
|
-
const toolsInfo = mdSection("Tools", `
|
|
22
|
-
You are provided access to the following tools and use them to plan coding tasks.
|
|
23
|
-
|
|
24
|
-
read_file: Use it to read a file from the codebase.
|
|
5
|
+
const system = `
|
|
6
|
+
You are a senior software architect creating implementation tasks.
|
|
25
7
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
8
|
+
Rules:
|
|
9
|
+
- Create atomic, deterministic tasks.
|
|
10
|
+
- Include exact file paths to create/modify.
|
|
11
|
+
- Prefer incremental edits over rewrites.
|
|
12
|
+
- Reuse existing code/patterns.
|
|
13
|
+
- Be concise but complete.
|
|
14
|
+
- Do not write code.
|
|
15
|
+
- Tasks must be directly executable by codegen agents.
|
|
16
|
+
|
|
17
|
+
${projectStateNote(isNewProject, "planner")}
|
|
18
|
+
`.trim();
|
|
19
|
+
const planTasksInfo = mdSection("PM Tasks", jsonBlock("Tasks", planTasks ?? []));
|
|
20
|
+
const toolsInfo = mdSection("Tools", `
|
|
21
|
+
- read_file: read file
|
|
22
|
+
- search: search codebase
|
|
23
|
+
- list_dir: list dirs
|
|
24
|
+
- submit_planner_tasks: Finalize planner output
|
|
31
25
|
`);
|
|
32
|
-
const planTasksInfo = mdSection("Plan Tasks", jsonBlock("Plan Tasks", planTasks ?? []));
|
|
33
26
|
const rendering = renderPlannerTaskFormatSection();
|
|
34
|
-
const
|
|
35
|
-
|
|
27
|
+
const projectConfiguration = mdSection("Project Config", [
|
|
28
|
+
jsonBlock("framework", plannerIndex.projectConfigs.frameworkConfig),
|
|
29
|
+
jsonBlock("runtime", plannerIndex.projectConfigs.runtimeConfig),
|
|
30
|
+
jsonBlock("tooling", plannerIndex.projectConfigs.toolingConfig),
|
|
31
|
+
jsonBlock("rendering", plannerIndex.projectConfigs.renderingConfig),
|
|
32
|
+
].join("\n"));
|
|
33
|
+
const context = mdSection("Relevant Context", jsonBlock("context", collectedContext ?? {}));
|
|
36
34
|
const sections = [
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
context,
|
|
40
|
-
projectConfiguration,
|
|
35
|
+
system,
|
|
36
|
+
planTasksInfo,
|
|
41
37
|
toolsInfo,
|
|
42
38
|
rendering,
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
39
|
+
projectConfiguration,
|
|
40
|
+
context,
|
|
41
|
+
plannerExamples,
|
|
46
42
|
];
|
|
47
43
|
return sections.join("\n\n---\n\n");
|
|
48
44
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"planner.prompt.js","sourceRoot":"","sources":["../../../src/ai/prompts/planner.prompt.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EA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AI,EAAE,CAAC,CAC7C,CAAC;IAEF,MAAM,QAAQ,GAAG;QACf,MAAM;QACN,aAAa;QACb,SAAS;QACT,SAAS;QACT,oBAAoB;QACpB,OAAO;QACP,eAAe;KAChB,CAAC;IAEF,OAAO,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;AACtC,CAAC,CAAC","sourcesContent":["import { CollectedContext } from \"../../types/context.types.js\";\r\nimport { PlannerIndex } from \"../../types/public.js\";\r\nimport { plannerExamples } from \"./examples/planner.examples.js\";\r\nimport {\r\n jsonBlock,\r\n mdSection,\r\n projectStateNote,\r\n renderPlannerTaskFormatSection,\r\n} from \"./helpers/promptParts.helper.js\";\r\n\r\nexport type PlanNodePromptParams = {\r\n planTasks: unknown[];\r\n collectedContext: CollectedContext;\r\n plannerIndex: PlannerIndex;\r\n isNewProject: boolean;\r\n};\r\n\r\nexport const plannerPrompt = (params: PlanNodePromptParams) => {\r\n const { planTasks, collectedContext, plannerIndex, isNewProject } = params;\r\n\r\n const system = `\r\n You are a senior software architect creating implementation tasks.\r\n\r\n Rules:\r\n - Create atomic, deterministic tasks.\r\n - Include exact file paths to create/modify.\r\n - Prefer incremental edits over rewrites.\r\n - Reuse existing code/patterns.\r\n - Be concise but complete.\r\n - Do not write code.\r\n - Tasks must be directly executable by codegen agents.\r\n\r\n ${projectStateNote(isNewProject, \"planner\")}\r\n `.trim();\r\n const planTasksInfo = mdSection(\r\n \"PM Tasks\",\r\n jsonBlock(\"Tasks\", planTasks ?? []),\r\n );\r\n\r\n const toolsInfo = mdSection(\r\n \"Tools\",\r\n `\r\n - read_file: read file\r\n - search: search codebase\r\n - list_dir: list dirs\r\n - submit_planner_tasks: Finalize planner output\r\n `,\r\n );\r\n\r\n const rendering = renderPlannerTaskFormatSection();\r\n\r\n const projectConfiguration = mdSection(\r\n \"Project Config\",\r\n [\r\n jsonBlock(\"framework\", plannerIndex.projectConfigs.frameworkConfig),\r\n\r\n jsonBlock(\"runtime\", plannerIndex.projectConfigs.runtimeConfig),\r\n\r\n jsonBlock(\"tooling\", plannerIndex.projectConfigs.toolingConfig),\r\n\r\n jsonBlock(\"rendering\", plannerIndex.projectConfigs.renderingConfig),\r\n ].join(\"\\n\"),\r\n );\r\n\r\n const context = mdSection(\r\n \"Relevant Context\",\r\n jsonBlock(\"context\", collectedContext ?? {}),\r\n );\r\n\r\n const sections = [\r\n system,\r\n planTasksInfo,\r\n toolsInfo,\r\n rendering,\r\n projectConfiguration,\r\n context,\r\n plannerExamples,\r\n ];\r\n\r\n return sections.join(\"\\n\\n---\\n\\n\");\r\n};\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validator.prompt.d.ts","sourceRoot":"","sources":["../../../src/ai/prompts/validator.prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"validator.prompt.d.ts","sourceRoot":"","sources":["../../../src/ai/prompts/validator.prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAOvD,MAAM,MAAM,0BAA0B,GAAG;IACvC,MAAM,EAAE,KAAK,CAAC;QACZ,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QACrB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QACzB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;KACzB,CAAC,CAAC;IACH,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAChD,cAAc,EAAE,cAAc,CAAC;CAChC,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,QAAQ,0BAA0B,WA0EjE,CAAC"}
|
|
@@ -1,54 +1,53 @@
|
|
|
1
|
-
import { jsonBlock, mdSection,
|
|
1
|
+
import { jsonBlock, mdSection, renderPlannerTaskFormatSection, } from "./helpers/promptParts.helper.js";
|
|
2
2
|
export const validatorPrompt = (params) => {
|
|
3
3
|
const { errors, history, validatorIndex } = params;
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
4
|
+
const system = `
|
|
5
|
+
You are a senior software engineer creating fix tasks for validation failures.
|
|
6
|
+
|
|
7
|
+
Rules:
|
|
8
|
+
- Fix ALL validation errors.
|
|
9
|
+
- Create atomic, deterministic tasks.
|
|
10
|
+
- Include exact file paths.
|
|
11
|
+
- Prefer incremental edits over rewrites.
|
|
12
|
+
- Reuse existing code/patterns.
|
|
13
|
+
- Be concise but complete.
|
|
14
|
+
- Do not write code.
|
|
15
|
+
- Tasks must be directly executable by codegen agents.
|
|
16
|
+
`.trim();
|
|
15
17
|
const renderedErrors = errors.length === 0
|
|
16
|
-
? "
|
|
18
|
+
? "none"
|
|
17
19
|
: errors
|
|
18
|
-
.map((
|
|
20
|
+
.map((e) => `type:${e.type} file:${e.filePath} msg:${e.message}`)
|
|
19
21
|
.join("\n");
|
|
20
22
|
const renderedHistory = history.length === 0
|
|
21
|
-
? "
|
|
22
|
-
: history
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
Validation Errors:
|
|
27
|
-
${renderedErrors}
|
|
23
|
+
? "none"
|
|
24
|
+
: history.map((h) => `file:${h.file} fix:${h.fix}`).join("\n");
|
|
25
|
+
const errorsInfo = mdSection("Validation", `
|
|
26
|
+
Errors:
|
|
27
|
+
${renderedErrors}
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
${renderedHistory}
|
|
31
|
-
|
|
32
|
-
`.trim());
|
|
29
|
+
History:
|
|
30
|
+
${renderedHistory}
|
|
31
|
+
`.trim());
|
|
33
32
|
const toolsInfo = mdSection("Tools", `
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
list_dir: Use it to list the directory structure of the codebase.
|
|
41
|
-
|
|
42
|
-
submit_planner_tasks: Use it to finalize and return the planner tasks for the code-generation agent.
|
|
43
|
-
`);
|
|
33
|
+
- read_file: read file
|
|
34
|
+
- search: search codebase
|
|
35
|
+
- list_dir: list dirs
|
|
36
|
+
- submit_planner_tasks: submit tasks
|
|
37
|
+
`.trim());
|
|
44
38
|
const rendering = renderPlannerTaskFormatSection();
|
|
39
|
+
const projectConfiguration = mdSection("Project Config", [
|
|
40
|
+
jsonBlock("framework", validatorIndex.projectConfigs.frameworkConfig),
|
|
41
|
+
jsonBlock("runtime", validatorIndex.projectConfigs.runtimeConfig),
|
|
42
|
+
jsonBlock("tooling", validatorIndex.projectConfigs.toolingConfig),
|
|
43
|
+
jsonBlock("rendering", validatorIndex.projectConfigs.renderingConfig),
|
|
44
|
+
].join("\n"));
|
|
45
45
|
const sections = [
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
projectConfiguration,
|
|
46
|
+
system,
|
|
47
|
+
errorsInfo,
|
|
49
48
|
toolsInfo,
|
|
50
49
|
rendering,
|
|
51
|
-
|
|
50
|
+
projectConfiguration,
|
|
52
51
|
];
|
|
53
52
|
return sections.join("\n\n---\n\n");
|
|
54
53
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validator.prompt.js","sourceRoot":"","sources":["../../../src/ai/prompts/validator.prompt.ts"],"names":[],"mappings":"AACA,OAAO,EACL,SAAS,EACT,SAAS,EACT,
|
|
1
|
+
{"version":3,"file":"validator.prompt.js","sourceRoot":"","sources":["../../../src/ai/prompts/validator.prompt.ts"],"names":[],"mappings":"AACA,OAAO,EACL,SAAS,EACT,SAAS,EACT,8BAA8B,GAC/B,MAAM,iCAAiC,CAAC;AAYzC,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,MAAkC,EAAE,EAAE;IACpE,MAAM,EAAE,MAAM,EAAE,OAA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CAAC;IAEF,MAAM,QAAQ,GAAG;QACf,MAAM;QACN,UAAU;QACV,SAAS;QACT,SAAS;QACT,oBAAoB;KACrB,CAAC;IAEF,OAAO,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;AACtC,CAAC,CAAC","sourcesContent":["import { ValidatorIndex } from \"../../types/public.js\";\r\nimport {\r\n jsonBlock,\r\n mdSection,\r\n renderPlannerTaskFormatSection,\r\n} from \"./helpers/promptParts.helper.js\";\r\n\r\nexport type ValidationNodePromptParams = {\r\n errors: Array<{\r\n type?: string | null;\r\n filePath?: string | null;\r\n message?: string | null;\r\n }>;\r\n history: Array<{ file?: string; fix?: string }>;\r\n validatorIndex: ValidatorIndex;\r\n};\r\n\r\nexport const validatorPrompt = (params: ValidationNodePromptParams) => {\r\n const { errors, history, validatorIndex } = params;\r\n\r\n const system = `\r\n You are a senior software engineer creating fix tasks for validation failures.\r\n\r\n Rules:\r\n - Fix ALL validation errors.\r\n - Create atomic, deterministic tasks.\r\n - Include exact file paths.\r\n - Prefer incremental edits over rewrites.\r\n - Reuse existing code/patterns.\r\n - Be concise but complete.\r\n - Do not write code.\r\n - Tasks must be directly executable by codegen agents.\r\n `.trim();\r\n\r\n const renderedErrors =\r\n errors.length === 0\r\n ? \"none\"\r\n : errors\r\n .map((e) => `type:${e.type} file:${e.filePath} msg:${e.message}`)\r\n .join(\"\\n\");\r\n\r\n const renderedHistory =\r\n history.length === 0\r\n ? \"none\"\r\n : history.map((h) => `file:${h.file} fix:${h.fix}`).join(\"\\n\");\r\n\r\n const errorsInfo = mdSection(\r\n \"Validation\",\r\n `\r\n Errors:\r\n ${renderedErrors}\r\n\r\n History:\r\n ${renderedHistory}\r\n `.trim(),\r\n );\r\n\r\n const toolsInfo = mdSection(\r\n \"Tools\",\r\n `\r\n - read_file: read file\r\n - search: search codebase\r\n - list_dir: list dirs\r\n - submit_planner_tasks: submit tasks\r\n `.trim(),\r\n );\r\n\r\n const rendering = renderPlannerTaskFormatSection();\r\n\r\n const projectConfiguration = mdSection(\r\n \"Project Config\",\r\n [\r\n jsonBlock(\"framework\", validatorIndex.projectConfigs.frameworkConfig),\r\n\r\n jsonBlock(\"runtime\", validatorIndex.projectConfigs.runtimeConfig),\r\n\r\n jsonBlock(\"tooling\", validatorIndex.projectConfigs.toolingConfig),\r\n\r\n jsonBlock(\"rendering\", validatorIndex.projectConfigs.renderingConfig),\r\n ].join(\"\\n\"),\r\n );\r\n\r\n const sections = [\r\n system,\r\n errorsInfo,\r\n toolsInfo,\r\n rendering,\r\n projectConfiguration,\r\n ];\r\n\r\n return sections.join(\"\\n\\n---\\n\\n\");\r\n};\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toolLoopContext.js","sourceRoot":"","sources":["../../../src/ai/toolLoop/toolLoopContext.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AAcjC,MAAM,CAAC,MAAM,sBAAsB,GAAoC;IACrE,uBAAuB,EAAE,GAAG;IAC5B,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"toolLoopContext.js","sourceRoot":"","sources":["../../../src/ai/toolLoop/toolLoopContext.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AAcjC,MAAM,CAAC,MAAM,sBAAsB,GAAoC;IACrE,uBAAuB,EAAE,GAAG;IAC5B,YAAY,EAAE,CAAC;IACf,aAAa,EAAE,MAAO;IACtB,mBAAmB,EAAE,KAAK;CAC3B,CAAC;AAEF,MAAM,SAAS,GAAG,CAAC,KAAa,EAAE,EAAE,CAClC,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAElE,MAAM,iBAAiB,GAAG,CAAC,WAAmB,EAAY,EAAE;IAC1D,MAAM,KAAK,GAAG,WAAW,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,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string;\n};\n\nexport type ToolLoopContextPolicy = {\n readFileDefaultMaxLines?: number;\n tailMessages?: number;\n maxModelChars?: number;\n logApproxModelChars?: boolean;\n};\n\nexport const DEFAULT_CONTEXT_POLICY: Required<ToolLoopContextPolicy> = {\n readFileDefaultMaxLines: 200,\n tailMessages: 6,\n maxModelChars: 120_000,\n logApproxModelChars: false,\n};\n\nconst sha256Hex = (value: string) =>\n crypto.createHash(\"sha256\").update(value, \"utf8\").digest(\"hex\");\n\nconst extractPatchFiles = (patchString: string): string[] => {\n const lines = patchString.replace(/\\r\\n/g, \"\\n\").split(\"\\n\");\n const files = new Set<string>();\n\n for (const line of lines) {\n const match =\n /^\\*\\*\\* (Update File|Add File|Delete File):\\s+(.+)$/.exec(line) ??\n /^\\*\\*\\* Move to:\\s+(.+)$/.exec(line);\n\n if (!match) continue;\n\n const filePath = (match[2] ?? match[1] ?? \"\").trim();\n if (filePath) files.add(filePath);\n }\n\n return [...files];\n};\n\nexport const redactFunctionCallArgs = (\n name: string,\n args: Record<string, unknown>,\n) => {\n if (name !== \"apply_patch\") return args;\n\n const patch = typeof args.patch_string === \"string\" ? args.patch_string : \"\";\n if (!patch) {\n return {\n ...args,\n patch_string: { omitted: true, chars: 0, sha256: sha256Hex(\"\"), files: [] },\n };\n }\n\n return {\n ...args,\n patch_string: {\n omitted: true,\n chars: patch.length,\n sha256: sha256Hex(patch),\n files: extractPatchFiles(patch),\n },\n };\n};\n\nconst isMemoryMessage = (item: any) => {\n const text = item?.parts?.[0]?.text;\n return (\n item?.role === \"model\" &&\n typeof text === \"string\" &&\n text.startsWith(\"MEMORY (tool trace summary):\")\n );\n};\n\nconst buildMemoryText = (events: ToolEvent[]) => {\n if (events.length === 0) return \"\";\n const lines = events.map((e) => `- ${e.summary}`);\n return `MEMORY (tool trace summary):\\n${lines.join(\"\\n\")}`;\n};\n\nexport const compactForModel = (input: {\n initialCount: number;\n modelContents: any[];\n toolEvents: ToolEvent[];\n policy: Required<ToolLoopContextPolicy>;\n}) => {\n const { initialCount, modelContents, toolEvents, policy } = input;\n\n const withoutOldMemory = modelContents.filter((c) => !isMemoryMessage(c));\n const tailStart = Math.max(\n initialCount,\n withoutOldMemory.length - policy.tailMessages,\n );\n\n const initial = withoutOldMemory.slice(0, initialCount);\n const tail = withoutOldMemory.slice(tailStart);\n const memoryText = buildMemoryText(toolEvents);\n const memory = memoryText\n ? [{ role: \"model\", parts: [{ text: memoryText }] }]\n : [];\n\n let compacted = [...initial, ...memory, ...tail];\n\n const maxChars = Math.max(10_000, policy.maxModelChars);\n while (JSON.stringify(compacted).length > maxChars) {\n const minLen = initial.length + memory.length + 1;\n if (compacted.length <= minLen) break;\n compacted = [\n ...initial,\n ...memory,\n ...compacted.slice(initial.length + memory.length + 1),\n ];\n }\n\n return compacted;\n};\n\nexport const normalizeReadFileArgs = (\n args: Record<string, unknown>,\n maxLines: number,\n) => {\n const requestedStart =\n args.start_line === undefined || args.start_line === null\n ? 1\n : Number(args.start_line);\n\n const requestedEnd =\n args.end_line === undefined || args.end_line === null\n ? undefined\n : Number(args.end_line);\n\n const start =\n Number.isFinite(requestedStart) && requestedStart > 0 ? requestedStart : 1;\n const cap = Math.max(1, Math.floor(maxLines));\n\n const desiredEnd =\n requestedEnd === undefined ||\n !Number.isFinite(requestedEnd) ||\n requestedEnd < start\n ? start + cap - 1\n : requestedEnd;\n\n const cappedEnd = Math.min(desiredEnd, start + cap - 1);\n const wasCapped =\n requestedEnd === undefined ||\n desiredEnd !== requestedEnd ||\n cappedEnd !== desiredEnd;\n\n return {\n effectiveArgs: { ...args, start_line: start, end_line: cappedEnd },\n start,\n end: cappedEnd,\n wasCapped,\n };\n};\n\nexport const getApplyPatchEventMeta = (args: Record<string, unknown>) => {\n const patch = typeof args.patch_string === \"string\" ? args.patch_string : \"\";\n return {\n chars: patch.length,\n sha256: sha256Hex(patch),\n files: extractPatchFiles(patch),\n };\n};\n\n"]}
|