@resolveio/server-lib 22.3.16 → 22.3.17
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/package.json +1 -1
- package/util/ai-qa-policy.d.ts +20 -0
- package/util/ai-qa-policy.js +76 -0
- package/util/ai-qa-policy.js.map +1 -1
package/package.json
CHANGED
package/util/ai-qa-policy.d.ts
CHANGED
|
@@ -21,6 +21,18 @@ export interface ResolveIORunnerBasicsOptions extends ResolveIOQaPolicyOptions {
|
|
|
21
21
|
maxContextBullets?: number;
|
|
22
22
|
maxRepairWaves?: number;
|
|
23
23
|
}
|
|
24
|
+
export interface ResolveIORunnerPromptInput extends ResolveIORunnerBasicsOptions {
|
|
25
|
+
objective?: string;
|
|
26
|
+
blockers?: string[];
|
|
27
|
+
relevantFiles?: string[];
|
|
28
|
+
evidence?: string[];
|
|
29
|
+
priorSummary?: string;
|
|
30
|
+
latestFailure?: string;
|
|
31
|
+
maxBlockers?: number;
|
|
32
|
+
maxFiles?: number;
|
|
33
|
+
maxEvidence?: number;
|
|
34
|
+
maxTextChars?: number;
|
|
35
|
+
}
|
|
24
36
|
export interface ResolveIORunnerContract {
|
|
25
37
|
context: ResolveIOQaPolicyContext;
|
|
26
38
|
sections: {
|
|
@@ -35,6 +47,12 @@ export interface ResolveIORunnerContract {
|
|
|
35
47
|
rules: string[];
|
|
36
48
|
promptLines: string[];
|
|
37
49
|
}
|
|
50
|
+
export interface ResolveIORunnerPromptBundle extends ResolveIORunnerContract {
|
|
51
|
+
objective: string;
|
|
52
|
+
contextLines: string[];
|
|
53
|
+
repairLines: string[];
|
|
54
|
+
fullPromptLines: string[];
|
|
55
|
+
}
|
|
38
56
|
export declare function normalizeResolveIOQaPolicyOptions(options?: ResolveIOQaPolicyOptions): Required<Omit<ResolveIOQaPolicyOptions, 'currentRoute' | 'currentContextMode' | 'customInstructions'>> & {
|
|
39
57
|
currentRoute: string;
|
|
40
58
|
currentContextMode: string;
|
|
@@ -44,3 +62,5 @@ export declare function buildResolveIOQaPolicyRules(options?: ResolveIOQaPolicyO
|
|
|
44
62
|
export declare function buildResolveIORunnerBasicsRules(options?: ResolveIORunnerBasicsOptions): string[];
|
|
45
63
|
export declare function buildResolveIORunnerContract(options?: ResolveIORunnerBasicsOptions): ResolveIORunnerContract;
|
|
46
64
|
export declare function buildResolveIORunnerPromptLines(options?: ResolveIORunnerBasicsOptions): string[];
|
|
65
|
+
export declare function buildResolveIORunnerPromptBundle(input?: ResolveIORunnerPromptInput): ResolveIORunnerPromptBundle;
|
|
66
|
+
export declare function buildResolveIORunnerRepairPromptLines(input?: ResolveIORunnerPromptInput): string[];
|
package/util/ai-qa-policy.js
CHANGED
|
@@ -10,6 +10,17 @@ var __assign = (this && this.__assign) || function () {
|
|
|
10
10
|
};
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
|
+
var __values = (this && this.__values) || function(o) {
|
|
14
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
15
|
+
if (m) return m.call(o);
|
|
16
|
+
if (o && typeof o.length === "number") return {
|
|
17
|
+
next: function () {
|
|
18
|
+
if (o && i >= o.length) o = void 0;
|
|
19
|
+
return { value: o && o[i++], done: !o };
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
23
|
+
};
|
|
13
24
|
var __read = (this && this.__read) || function (o, n) {
|
|
14
25
|
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
15
26
|
if (!m) return o;
|
|
@@ -41,6 +52,8 @@ exports.buildResolveIOQaPolicyRules = buildResolveIOQaPolicyRules;
|
|
|
41
52
|
exports.buildResolveIORunnerBasicsRules = buildResolveIORunnerBasicsRules;
|
|
42
53
|
exports.buildResolveIORunnerContract = buildResolveIORunnerContract;
|
|
43
54
|
exports.buildResolveIORunnerPromptLines = buildResolveIORunnerPromptLines;
|
|
55
|
+
exports.buildResolveIORunnerPromptBundle = buildResolveIORunnerPromptBundle;
|
|
56
|
+
exports.buildResolveIORunnerRepairPromptLines = buildResolveIORunnerRepairPromptLines;
|
|
44
57
|
function normalizeOptionalString(value) {
|
|
45
58
|
return String(value || '').replace(/\s+/g, ' ').trim();
|
|
46
59
|
}
|
|
@@ -52,6 +65,36 @@ function normalizePositiveInteger(value, fallback, min, max) {
|
|
|
52
65
|
var rounded = Number(numeric.toFixed(0));
|
|
53
66
|
return Math.max(min, Math.min(max, rounded));
|
|
54
67
|
}
|
|
68
|
+
function normalizeTextLine(value, maxChars) {
|
|
69
|
+
return normalizeOptionalString(value).slice(0, maxChars).trim();
|
|
70
|
+
}
|
|
71
|
+
function normalizeTextList(values, limit, maxChars) {
|
|
72
|
+
var e_1, _a;
|
|
73
|
+
if (!Array.isArray(values)) {
|
|
74
|
+
return [];
|
|
75
|
+
}
|
|
76
|
+
var result = [];
|
|
77
|
+
try {
|
|
78
|
+
for (var values_1 = __values(values), values_1_1 = values_1.next(); !values_1_1.done; values_1_1 = values_1.next()) {
|
|
79
|
+
var value = values_1_1.value;
|
|
80
|
+
var normalized = normalizeTextLine(value, maxChars);
|
|
81
|
+
if (normalized && !result.includes(normalized)) {
|
|
82
|
+
result.push(normalized);
|
|
83
|
+
}
|
|
84
|
+
if (result.length >= limit) {
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
90
|
+
finally {
|
|
91
|
+
try {
|
|
92
|
+
if (values_1_1 && !values_1_1.done && (_a = values_1.return)) _a.call(values_1);
|
|
93
|
+
}
|
|
94
|
+
finally { if (e_1) throw e_1.error; }
|
|
95
|
+
}
|
|
96
|
+
return result;
|
|
97
|
+
}
|
|
55
98
|
function normalizeResolveIOQaPolicyOptions(options) {
|
|
56
99
|
if (options === void 0) { options = {}; }
|
|
57
100
|
return {
|
|
@@ -170,5 +213,38 @@ function buildResolveIORunnerPromptLines(options) {
|
|
|
170
213
|
if (options === void 0) { options = {}; }
|
|
171
214
|
return buildResolveIORunnerContract(options).promptLines;
|
|
172
215
|
}
|
|
216
|
+
function buildResolveIORunnerPromptBundle(input) {
|
|
217
|
+
if (input === void 0) { input = {}; }
|
|
218
|
+
var contract = buildResolveIORunnerContract(input);
|
|
219
|
+
var maxTextChars = normalizePositiveInteger(input.maxTextChars, 900, 160, 2400);
|
|
220
|
+
var objective = normalizeTextLine(input.objective, maxTextChars)
|
|
221
|
+
|| 'Complete the requested ResolveIO runner task with minimal, verified changes.';
|
|
222
|
+
var priorSummary = normalizeTextLine(input.priorSummary, maxTextChars);
|
|
223
|
+
var latestFailure = normalizeTextLine(input.latestFailure, maxTextChars);
|
|
224
|
+
var blockers = normalizeTextList(input.blockers, normalizePositiveInteger(input.maxBlockers, 5, 1, 12), maxTextChars);
|
|
225
|
+
var relevantFiles = normalizeTextList(input.relevantFiles, normalizePositiveInteger(input.maxFiles, 12, 1, 30), 260);
|
|
226
|
+
var evidence = normalizeTextList(input.evidence, normalizePositiveInteger(input.maxEvidence, 8, 1, 20), maxTextChars);
|
|
227
|
+
var contextLines = __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([
|
|
228
|
+
"Objective: ".concat(objective)
|
|
229
|
+
], __read((priorSummary ? ["Prior summary: ".concat(priorSummary)] : [])), false), __read((latestFailure ? ["Latest failure: ".concat(latestFailure)] : [])), false), __read((blockers.length ? __spreadArray(['Active blockers:'], __read(blockers.map(function (line) { return "- ".concat(line); })), false) : [])), false), __read((relevantFiles.length ? __spreadArray(['Relevant files:'], __read(relevantFiles.map(function (line) { return "- ".concat(line); })), false) : [])), false), __read((evidence.length ? __spreadArray(['Known evidence:'], __read(evidence.map(function (line) { return "- ".concat(line); })), false) : [])), false);
|
|
230
|
+
var repairLines = blockers.length
|
|
231
|
+
? [
|
|
232
|
+
'Mandatory repair contract:',
|
|
233
|
+
'- Address each active blocker before unrelated work.',
|
|
234
|
+
'- For each blocker, mark resolved, proven false, or blocked.',
|
|
235
|
+
'- Attach code, data, command, browser, screenshot, or trace proof for each blocker.',
|
|
236
|
+
'- If a blocker repeats with no meaningful diff/evidence change, park instead of starting another broad attempt.'
|
|
237
|
+
]
|
|
238
|
+
: [];
|
|
239
|
+
var fullPromptLines = __spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(contract.promptLines), false), [
|
|
240
|
+
'',
|
|
241
|
+
'Runner task context:'
|
|
242
|
+
], false), __read(contextLines), false), __read((repairLines.length ? __spreadArray([''], __read(repairLines), false) : [])), false);
|
|
243
|
+
return __assign(__assign({}, contract), { objective: objective, contextLines: contextLines, repairLines: repairLines, fullPromptLines: fullPromptLines });
|
|
244
|
+
}
|
|
245
|
+
function buildResolveIORunnerRepairPromptLines(input) {
|
|
246
|
+
if (input === void 0) { input = {}; }
|
|
247
|
+
return buildResolveIORunnerPromptBundle(input).repairLines;
|
|
248
|
+
}
|
|
173
249
|
|
|
174
250
|
//# sourceMappingURL=ai-qa-policy.js.map
|
package/util/ai-qa-policy.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/util/ai-qa-policy.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0DA,8EAoBC;AAED,kEA+BC;AAED,0EAEC;AAED,oEA8EC;AAED,0EAEC;AA1JD,SAAS,uBAAuB,CAAC,KAAU;IAC1C,OAAO,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;AACxD,CAAC;AAED,SAAS,wBAAwB,CAAC,KAAU,EAAE,QAAgB,EAAE,GAAW,EAAE,GAAW;IACvF,IAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAC9B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;QAC/B,OAAO,QAAQ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AAC;IACN,IAAM,UAAU,GAAG;QAClB,iLAAiL;QACjL,gLAAgL;KAChL,CAAC;IACF,IAAM,QAAQ,GAAG;QAChB,YAAY,cAAA;QACZ,eAAe,iBAAA;QACf,mBAAmB,qBAAA;QACnB,UAAU,YAAA;QACV,QAAQ,UAAA;QACR,gBAAgB,kBAAA;QAChB,UAAU,YAAA;KACV,CAAC;IACF,IAAM,KAAK,gHACP,YAAY,kBACZ,eAAe,kBACf,mBAAmB,kBACnB,UAAU,kBACV,QAAQ,kBACR,gBAAgB,kBAChB,UAAU,SACb,CAAC;IACF,IAAM,WAAW;QAChB,4CAAqC,OAAO,OAAI;cAC7C,KAAK,CAAC,GAAG,CAAC,UAAC,IAAI,IAAK,OAAA,YAAK,IAAI,CAAE,EAAX,CAAW,CAAC,SACnC,CAAC;IACF,OAAO;QACN,OAAO,SAAA;QACP,QAAQ,UAAA;QACR,KAAK,OAAA;QACL,WAAW,aAAA;KACX,CAAC;AACH,CAAC;AAED,SAAgB,+BAA+B,CAAC,OAA0C;IAA1C,wBAAA,EAAA,YAA0C;IACzF,OAAO,4BAA4B,CAAC,OAAO,CAAC,CAAC,WAAW,CAAC;AAC1D,CAAC","file":"ai-qa-policy.js","sourcesContent":["export type ResolveIOQaPolicyContext =\n\t| 'support_ticket'\n\t| 'aicoder_dashboard'\n\t| 'ai_terminal'\n\t| 'general';\n\nexport interface ResolveIOQaPolicyOptions {\n\tcontext?: ResolveIOQaPolicyContext;\n\tincludeDevServerRules?: boolean;\n\tqaRepairEnabled?: boolean;\n\tqaEvidenceRequired?: boolean;\n\tqaDistinctScreenshotRequired?: boolean;\n\tqaFailFastCompile?: boolean;\n\tqaLiveDataRequired?: boolean;\n\tqaSelfRepairMaxWaves?: number;\n\tcurrentRoute?: string;\n\tcurrentContextMode?: string;\n\tcustomInstructions?: string[];\n}\n\nexport interface ResolveIORunnerBasicsOptions extends ResolveIOQaPolicyOptions {\n\tincludeQaPolicy?: boolean;\n\tincludeTokenDiscipline?: boolean;\n\tincludeDependencyBootstrap?: boolean;\n\tincludeRepairLoop?: boolean;\n\tincludeEvidenceContract?: boolean;\n\tmaxContextBullets?: number;\n\tmaxRepairWaves?: number;\n}\n\nexport interface ResolveIORunnerContract {\n\tcontext: ResolveIOQaPolicyContext;\n\tsections: {\n\t\trunnerBasics: string[];\n\t\ttokenDiscipline: string[];\n\t\tdependencyBootstrap: string[];\n\t\trepairLoop: string[];\n\t\tqaPolicy: string[];\n\t\tevidenceContract: string[];\n\t\tfinalNotes: string[];\n\t};\n\trules: string[];\n\tpromptLines: string[];\n}\n\nfunction normalizeOptionalString(value: any): string {\n\treturn String(value || '').replace(/\\s+/g, ' ').trim();\n}\n\nfunction normalizePositiveInteger(value: any, fallback: number, min: number, max: number): number {\n\tconst numeric = Number(value);\n\tif (!Number.isFinite(numeric)) {\n\t\treturn fallback;\n\t}\n\tconst rounded = Number(numeric.toFixed(0));\n\treturn Math.max(min, Math.min(max, rounded));\n}\n\nexport function normalizeResolveIOQaPolicyOptions(options: ResolveIOQaPolicyOptions = {}): Required<Omit<ResolveIOQaPolicyOptions, 'currentRoute' | 'currentContextMode' | 'customInstructions'>> & {\n\tcurrentRoute: string;\n\tcurrentContextMode: string;\n\tcustomInstructions: string[];\n} {\n\treturn {\n\t\tcontext: options.context || 'general',\n\t\tincludeDevServerRules: options.includeDevServerRules === true,\n\t\tqaRepairEnabled: options.qaRepairEnabled !== false,\n\t\tqaEvidenceRequired: options.qaEvidenceRequired !== false,\n\t\tqaDistinctScreenshotRequired: options.qaDistinctScreenshotRequired !== false,\n\t\tqaFailFastCompile: options.qaFailFastCompile !== false,\n\t\tqaLiveDataRequired: options.qaLiveDataRequired !== false,\n\t\tqaSelfRepairMaxWaves: normalizePositiveInteger(options.qaSelfRepairMaxWaves, 3, 1, 6),\n\t\tcurrentRoute: normalizeOptionalString(options.currentRoute),\n\t\tcurrentContextMode: normalizeOptionalString(options.currentContextMode),\n\t\tcustomInstructions: Array.isArray(options.customInstructions)\n\t\t\t? options.customInstructions.map(normalizeOptionalString).filter(Boolean).slice(0, 12)\n\t\t\t: []\n\t};\n}\n\nexport function buildResolveIOQaPolicyRules(options: ResolveIOQaPolicyOptions = {}): string[] {\n\tconst policy = normalizeResolveIOQaPolicyOptions(options);\n\tconst rules: string[] = [];\n\tif (policy.includeDevServerRules) {\n\t\trules.push(\n\t\t\t'When browser/localhost QA needs long-running commands like `npm run server`, `npm run client`, `npm run dev`, `ng serve`, `vite`, or `nodemon`, start them as managed background processes with log files and PIDs; do not leave foreground dev-server commands as the active shell tool.',\n\t\t\t'Before localhost/browser QA, source `.resolveio-support-tools/env.sh` when present. It supplies shared EC2 browser cache settings, `PUPPETEER_EXECUTABLE_PATH`/`CHROME_BIN`, Mongo wrappers, and `RESOLVEIO_SUPPORT_QA_CLIENT_PORT`/`RESOLVEIO_SUPPORT_QA_CLIENT_URL` for non-conflicting client ports.',\n\t\t\t'When launching Puppeteer or Playwright on workers, pass `executablePath: process.env.PUPPETEER_EXECUTABLE_PATH || process.env.CHROME_BIN` if either env var is set. Do not download a fresh browser before checking these env vars and `PUPPETEER_CACHE_DIR`.',\n\t\t\t'Use the managed-server pattern for localhost QA: `command > .build-output/<name>.log 2>&1 & PID=$!; trap \"kill $PID 2>/dev/null || true\" EXIT; wait for the port with curl; run browser checks; then kill/wait the PID`. Prefer `npm run client` or `./start_client.sh`; those scripts honor `RESOLVEIO_SUPPORT_QA_CLIENT_PORT` and `PORT`. Never run `ng serve ... | tee ...` or another dev server as a foreground command.'\n\t\t);\n\t}\n\tif (policy.qaFailFastCompile) {\n\t\trules.push('Before browser QA, run the fastest compile/type/startup checks that can prove the app can load. Fix compile/startup failures before launching browser QA.');\n\t}\n\tif (policy.qaRepairEnabled) {\n\t\trules.push(`If compile, startup, browser, or live-data QA fails, run a targeted repair wave for the exact failing route/action/data state, then rerun that same failed step before continuing. Limit self-repair to ${policy.qaSelfRepairMaxWaves} focused waves before returning the precise blocker.`);\n\t}\n\tif (policy.qaLiveDataRequired) {\n\t\trules.push('For bug fixes and data/publication changes, test against available live app data or a faithful seeded record; do not rely only on static inspection when the user reported a runtime workflow problem.');\n\t}\n\tif (policy.qaDistinctScreenshotRequired) {\n\t\trules.push('Capture one screenshot or trace for each distinct changed customer-facing feature, screen, workflow state, or data result. Do not repeat equivalent screenshots for multiple records unless record-specific behavior changed.');\n\t}\n\tif (policy.qaEvidenceRequired) {\n\t\trules.push('Final notes must list the exact QA command, route, account/data used, screenshot/trace/log paths, and result for each changed behavior; if browser QA is not applicable, say why and provide the compile/data proof used instead.');\n\t}\n\tif (policy.currentRoute) {\n\t\trules.push(`Current app context route from the AI terminal is ${policy.currentRoute}${policy.currentContextMode ? ` (${policy.currentContextMode})` : ''}; start QA there when the request refers to this page or current screen.`);\n\t}\n\trules.push(...policy.customInstructions);\n\treturn rules;\n}\n\nexport function buildResolveIORunnerBasicsRules(options: ResolveIORunnerBasicsOptions = {}): string[] {\n\treturn buildResolveIORunnerContract(options).rules;\n}\n\nexport function buildResolveIORunnerContract(options: ResolveIORunnerBasicsOptions = {}): ResolveIORunnerContract {\n\tconst maxContextBullets = normalizePositiveInteger(options.maxContextBullets, 8, 3, 20);\n\tconst maxRepairWaves = normalizePositiveInteger(\n\t\toptions.maxRepairWaves ?? options.qaSelfRepairMaxWaves,\n\t\t3,\n\t\t1,\n\t\t6\n\t);\n\tconst context = options.context || 'general';\n\tconst runnerBasics = [\n\t\t'Use repo-local patterns first: read the closest existing implementation, matching tests, model/schema, method/publication, and UI route before editing.',\n\t\t'Make the smallest complete change that satisfies the request; avoid broad refactors, config churn, dependency changes, and generated-file edits unless the workflow explicitly requires regeneration.',\n\t\t'Before returning, state what changed, how it was verified, remaining blockers, and exact artifact paths in final notes.'\n\t];\n\tconst tokenDiscipline = options.includeTokenDiscipline !== false\n\t\t? [\n\t\t\t`Keep context lean: summarize prior history into at most ${maxContextBullets} bullets, retrieve specific files on demand, and do not paste full logs, lockfiles, generated files, or stale ticket/email chains unless they are the current blocker evidence.`,\n\t\t\t'Prefer targeted search/read commands over loading broad directories. If a command returns noisy output, summarize the useful lines and continue with narrower reads.',\n\t\t\t'On retries, carry only the active blocker contract, changed-file list, relevant diff/evidence summary, and latest failing command output. Do not restart with a clean-slate mega prompt.',\n\t\t\t'Stop autonomous retries when the same normalized blocker repeats without meaningful diff or evidence improvement; park with a precise blocker instead of burning tokens.'\n\t\t]\n\t\t: [];\n\tconst dependencyBootstrap = options.includeDependencyBootstrap !== false\n\t\t? [\n\t\t\t'Reuse existing dependency caches and hydrated node_modules when available. Prefer npm install --force with the configured npm cache; do not use npm ci unless the workflow explicitly requires it.',\n\t\t\t'Before reinstalling or downloading browsers, check the existing workspace cache, shared node_modules, PUPPETEER_EXECUTABLE_PATH, CHROME_BIN, PUPPETEER_CACHE_DIR, and project-provided bootstrap scripts.'\n\t\t]\n\t\t: [];\n\tconst repairLoop = options.includeRepairLoop !== false\n\t\t? [\n\t\t\t`Use targeted repair waves: compile/startup blocker, browser route/action blocker, data/publication blocker, and review blocker each get a focused repair, then rerun the exact failed step. Limit this to ${maxRepairWaves} focused waves before returning a precise blocker.`,\n\t\t\t'Repair all instances of a detected blocker class in the touched scope, not only the first occurrence.'\n\t\t]\n\t\t: [];\n\tconst qaPolicy = options.includeQaPolicy !== false\n\t\t? buildResolveIOQaPolicyRules({\n\t\t\t...options,\n\t\t\tqaSelfRepairMaxWaves: maxRepairWaves\n\t\t})\n\t\t: [];\n\tconst evidenceContract = options.includeEvidenceContract !== false\n\t\t? [\n\t\t\t'Evidence must be customer/workflow oriented: routes, buttons, pages, data states, screenshots/traces, command results, and assertions. Do not expose internal file names, backend paths, stack traces, or implementation chatter in customer-facing text.',\n\t\t\t'For UI-facing changes, capture one screenshot or trace per distinct changed feature/workflow; for data-only changes, provide live-data or seeded-data assertion proof.'\n\t\t]\n\t\t: [];\n\tconst finalNotes = [\n\t\t'Final notes must include: changed behavior, touched functional areas, exact commands run, exact QA route/data state, screenshot/trace/log paths, and remaining blockers if any.',\n\t\t'If work is parked, final notes must name the blocker class, last failing command/artifact, why another autonomous attempt would repeat, and the smallest manual action needed.'\n\t];\n\tconst sections = {\n\t\trunnerBasics,\n\t\ttokenDiscipline,\n\t\tdependencyBootstrap,\n\t\trepairLoop,\n\t\tqaPolicy,\n\t\tevidenceContract,\n\t\tfinalNotes\n\t};\n\tconst rules = [\n\t\t...runnerBasics,\n\t\t...tokenDiscipline,\n\t\t...dependencyBootstrap,\n\t\t...repairLoop,\n\t\t...qaPolicy,\n\t\t...evidenceContract,\n\t\t...finalNotes\n\t];\n\tconst promptLines = [\n\t\t`ResolveIO shared runner contract (${context}):`,\n\t\t...rules.map((rule) => `- ${rule}`)\n\t];\n\treturn {\n\t\tcontext,\n\t\tsections,\n\t\trules,\n\t\tpromptLines\n\t};\n}\n\nexport function buildResolveIORunnerPromptLines(options: ResolveIORunnerBasicsOptions = {}): string[] {\n\treturn buildResolveIORunnerContract(options).promptLines;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/util/ai-qa-policy.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmGA,8EAoBC;AAED,kEA+BC;AAED,0EAEC;AAED,oEA8EC;AAED,0EAEC;AAED,4EAyCC;AAED,sFAEC;AA9ND,SAAS,uBAAuB,CAAC,KAAU;IAC1C,OAAO,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;AACxD,CAAC;AAED,SAAS,wBAAwB,CAAC,KAAU,EAAE,QAAgB,EAAE,GAAW,EAAE,GAAW;IACvF,IAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAC9B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;QAC/B,OAAO,QAAQ,CAAC;IACjB,CAAC;IACD,IAAM,OAAO,GAAG,MAAM,CAAC,OAAO,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,CAAC;AAED,SAAgB,qCAAqC,CAAC,KAAsC;IAAtC,sBAAA,EAAA,UAAsC;IAC3F,OAAO,gCAAgC,CAAC,KAAK,CAAC,CAAC,WAAW,CAAC;AAC5D,CAAC","file":"ai-qa-policy.js","sourcesContent":["export type ResolveIOQaPolicyContext =\n\t| 'support_ticket'\n\t| 'aicoder_dashboard'\n\t| 'ai_terminal'\n\t| 'general';\n\nexport interface ResolveIOQaPolicyOptions {\n\tcontext?: ResolveIOQaPolicyContext;\n\tincludeDevServerRules?: boolean;\n\tqaRepairEnabled?: boolean;\n\tqaEvidenceRequired?: boolean;\n\tqaDistinctScreenshotRequired?: boolean;\n\tqaFailFastCompile?: boolean;\n\tqaLiveDataRequired?: boolean;\n\tqaSelfRepairMaxWaves?: number;\n\tcurrentRoute?: string;\n\tcurrentContextMode?: string;\n\tcustomInstructions?: string[];\n}\n\nexport interface ResolveIORunnerBasicsOptions extends ResolveIOQaPolicyOptions {\n\tincludeQaPolicy?: boolean;\n\tincludeTokenDiscipline?: boolean;\n\tincludeDependencyBootstrap?: boolean;\n\tincludeRepairLoop?: boolean;\n\tincludeEvidenceContract?: boolean;\n\tmaxContextBullets?: number;\n\tmaxRepairWaves?: number;\n}\n\nexport interface ResolveIORunnerPromptInput extends ResolveIORunnerBasicsOptions {\n\tobjective?: string;\n\tblockers?: string[];\n\trelevantFiles?: string[];\n\tevidence?: string[];\n\tpriorSummary?: string;\n\tlatestFailure?: string;\n\tmaxBlockers?: number;\n\tmaxFiles?: number;\n\tmaxEvidence?: number;\n\tmaxTextChars?: number;\n}\n\nexport interface ResolveIORunnerContract {\n\tcontext: ResolveIOQaPolicyContext;\n\tsections: {\n\t\trunnerBasics: string[];\n\t\ttokenDiscipline: string[];\n\t\tdependencyBootstrap: string[];\n\t\trepairLoop: string[];\n\t\tqaPolicy: string[];\n\t\tevidenceContract: string[];\n\t\tfinalNotes: string[];\n\t};\n\trules: string[];\n\tpromptLines: string[];\n}\n\nexport interface ResolveIORunnerPromptBundle extends ResolveIORunnerContract {\n\tobjective: string;\n\tcontextLines: string[];\n\trepairLines: string[];\n\tfullPromptLines: string[];\n}\n\nfunction normalizeOptionalString(value: any): string {\n\treturn String(value || '').replace(/\\s+/g, ' ').trim();\n}\n\nfunction normalizePositiveInteger(value: any, fallback: number, min: number, max: number): number {\n\tconst numeric = Number(value);\n\tif (!Number.isFinite(numeric)) {\n\t\treturn fallback;\n\t}\n\tconst rounded = Number(numeric.toFixed(0));\n\treturn Math.max(min, Math.min(max, rounded));\n}\n\nfunction normalizeTextLine(value: any, maxChars: number): string {\n\treturn normalizeOptionalString(value).slice(0, maxChars).trim();\n}\n\nfunction normalizeTextList(values: any, limit: number, maxChars: number): string[] {\n\tif (!Array.isArray(values)) {\n\t\treturn [];\n\t}\n\tconst result: string[] = [];\n\tfor (const value of values) {\n\t\tconst normalized = normalizeTextLine(value, maxChars);\n\t\tif (normalized && !result.includes(normalized)) {\n\t\t\tresult.push(normalized);\n\t\t}\n\t\tif (result.length >= limit) {\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn result;\n}\n\nexport function normalizeResolveIOQaPolicyOptions(options: ResolveIOQaPolicyOptions = {}): Required<Omit<ResolveIOQaPolicyOptions, 'currentRoute' | 'currentContextMode' | 'customInstructions'>> & {\n\tcurrentRoute: string;\n\tcurrentContextMode: string;\n\tcustomInstructions: string[];\n} {\n\treturn {\n\t\tcontext: options.context || 'general',\n\t\tincludeDevServerRules: options.includeDevServerRules === true,\n\t\tqaRepairEnabled: options.qaRepairEnabled !== false,\n\t\tqaEvidenceRequired: options.qaEvidenceRequired !== false,\n\t\tqaDistinctScreenshotRequired: options.qaDistinctScreenshotRequired !== false,\n\t\tqaFailFastCompile: options.qaFailFastCompile !== false,\n\t\tqaLiveDataRequired: options.qaLiveDataRequired !== false,\n\t\tqaSelfRepairMaxWaves: normalizePositiveInteger(options.qaSelfRepairMaxWaves, 3, 1, 6),\n\t\tcurrentRoute: normalizeOptionalString(options.currentRoute),\n\t\tcurrentContextMode: normalizeOptionalString(options.currentContextMode),\n\t\tcustomInstructions: Array.isArray(options.customInstructions)\n\t\t\t? options.customInstructions.map(normalizeOptionalString).filter(Boolean).slice(0, 12)\n\t\t\t: []\n\t};\n}\n\nexport function buildResolveIOQaPolicyRules(options: ResolveIOQaPolicyOptions = {}): string[] {\n\tconst policy = normalizeResolveIOQaPolicyOptions(options);\n\tconst rules: string[] = [];\n\tif (policy.includeDevServerRules) {\n\t\trules.push(\n\t\t\t'When browser/localhost QA needs long-running commands like `npm run server`, `npm run client`, `npm run dev`, `ng serve`, `vite`, or `nodemon`, start them as managed background processes with log files and PIDs; do not leave foreground dev-server commands as the active shell tool.',\n\t\t\t'Before localhost/browser QA, source `.resolveio-support-tools/env.sh` when present. It supplies shared EC2 browser cache settings, `PUPPETEER_EXECUTABLE_PATH`/`CHROME_BIN`, Mongo wrappers, and `RESOLVEIO_SUPPORT_QA_CLIENT_PORT`/`RESOLVEIO_SUPPORT_QA_CLIENT_URL` for non-conflicting client ports.',\n\t\t\t'When launching Puppeteer or Playwright on workers, pass `executablePath: process.env.PUPPETEER_EXECUTABLE_PATH || process.env.CHROME_BIN` if either env var is set. Do not download a fresh browser before checking these env vars and `PUPPETEER_CACHE_DIR`.',\n\t\t\t'Use the managed-server pattern for localhost QA: `command > .build-output/<name>.log 2>&1 & PID=$!; trap \"kill $PID 2>/dev/null || true\" EXIT; wait for the port with curl; run browser checks; then kill/wait the PID`. Prefer `npm run client` or `./start_client.sh`; those scripts honor `RESOLVEIO_SUPPORT_QA_CLIENT_PORT` and `PORT`. Never run `ng serve ... | tee ...` or another dev server as a foreground command.'\n\t\t);\n\t}\n\tif (policy.qaFailFastCompile) {\n\t\trules.push('Before browser QA, run the fastest compile/type/startup checks that can prove the app can load. Fix compile/startup failures before launching browser QA.');\n\t}\n\tif (policy.qaRepairEnabled) {\n\t\trules.push(`If compile, startup, browser, or live-data QA fails, run a targeted repair wave for the exact failing route/action/data state, then rerun that same failed step before continuing. Limit self-repair to ${policy.qaSelfRepairMaxWaves} focused waves before returning the precise blocker.`);\n\t}\n\tif (policy.qaLiveDataRequired) {\n\t\trules.push('For bug fixes and data/publication changes, test against available live app data or a faithful seeded record; do not rely only on static inspection when the user reported a runtime workflow problem.');\n\t}\n\tif (policy.qaDistinctScreenshotRequired) {\n\t\trules.push('Capture one screenshot or trace for each distinct changed customer-facing feature, screen, workflow state, or data result. Do not repeat equivalent screenshots for multiple records unless record-specific behavior changed.');\n\t}\n\tif (policy.qaEvidenceRequired) {\n\t\trules.push('Final notes must list the exact QA command, route, account/data used, screenshot/trace/log paths, and result for each changed behavior; if browser QA is not applicable, say why and provide the compile/data proof used instead.');\n\t}\n\tif (policy.currentRoute) {\n\t\trules.push(`Current app context route from the AI terminal is ${policy.currentRoute}${policy.currentContextMode ? ` (${policy.currentContextMode})` : ''}; start QA there when the request refers to this page or current screen.`);\n\t}\n\trules.push(...policy.customInstructions);\n\treturn rules;\n}\n\nexport function buildResolveIORunnerBasicsRules(options: ResolveIORunnerBasicsOptions = {}): string[] {\n\treturn buildResolveIORunnerContract(options).rules;\n}\n\nexport function buildResolveIORunnerContract(options: ResolveIORunnerBasicsOptions = {}): ResolveIORunnerContract {\n\tconst maxContextBullets = normalizePositiveInteger(options.maxContextBullets, 8, 3, 20);\n\tconst maxRepairWaves = normalizePositiveInteger(\n\t\toptions.maxRepairWaves ?? options.qaSelfRepairMaxWaves,\n\t\t3,\n\t\t1,\n\t\t6\n\t);\n\tconst context = options.context || 'general';\n\tconst runnerBasics = [\n\t\t'Use repo-local patterns first: read the closest existing implementation, matching tests, model/schema, method/publication, and UI route before editing.',\n\t\t'Make the smallest complete change that satisfies the request; avoid broad refactors, config churn, dependency changes, and generated-file edits unless the workflow explicitly requires regeneration.',\n\t\t'Before returning, state what changed, how it was verified, remaining blockers, and exact artifact paths in final notes.'\n\t];\n\tconst tokenDiscipline = options.includeTokenDiscipline !== false\n\t\t? [\n\t\t\t`Keep context lean: summarize prior history into at most ${maxContextBullets} bullets, retrieve specific files on demand, and do not paste full logs, lockfiles, generated files, or stale ticket/email chains unless they are the current blocker evidence.`,\n\t\t\t'Prefer targeted search/read commands over loading broad directories. If a command returns noisy output, summarize the useful lines and continue with narrower reads.',\n\t\t\t'On retries, carry only the active blocker contract, changed-file list, relevant diff/evidence summary, and latest failing command output. Do not restart with a clean-slate mega prompt.',\n\t\t\t'Stop autonomous retries when the same normalized blocker repeats without meaningful diff or evidence improvement; park with a precise blocker instead of burning tokens.'\n\t\t]\n\t\t: [];\n\tconst dependencyBootstrap = options.includeDependencyBootstrap !== false\n\t\t? [\n\t\t\t'Reuse existing dependency caches and hydrated node_modules when available. Prefer npm install --force with the configured npm cache; do not use npm ci unless the workflow explicitly requires it.',\n\t\t\t'Before reinstalling or downloading browsers, check the existing workspace cache, shared node_modules, PUPPETEER_EXECUTABLE_PATH, CHROME_BIN, PUPPETEER_CACHE_DIR, and project-provided bootstrap scripts.'\n\t\t]\n\t\t: [];\n\tconst repairLoop = options.includeRepairLoop !== false\n\t\t? [\n\t\t\t`Use targeted repair waves: compile/startup blocker, browser route/action blocker, data/publication blocker, and review blocker each get a focused repair, then rerun the exact failed step. Limit this to ${maxRepairWaves} focused waves before returning a precise blocker.`,\n\t\t\t'Repair all instances of a detected blocker class in the touched scope, not only the first occurrence.'\n\t\t]\n\t\t: [];\n\tconst qaPolicy = options.includeQaPolicy !== false\n\t\t? buildResolveIOQaPolicyRules({\n\t\t\t...options,\n\t\t\tqaSelfRepairMaxWaves: maxRepairWaves\n\t\t})\n\t\t: [];\n\tconst evidenceContract = options.includeEvidenceContract !== false\n\t\t? [\n\t\t\t'Evidence must be customer/workflow oriented: routes, buttons, pages, data states, screenshots/traces, command results, and assertions. Do not expose internal file names, backend paths, stack traces, or implementation chatter in customer-facing text.',\n\t\t\t'For UI-facing changes, capture one screenshot or trace per distinct changed feature/workflow; for data-only changes, provide live-data or seeded-data assertion proof.'\n\t\t]\n\t\t: [];\n\tconst finalNotes = [\n\t\t'Final notes must include: changed behavior, touched functional areas, exact commands run, exact QA route/data state, screenshot/trace/log paths, and remaining blockers if any.',\n\t\t'If work is parked, final notes must name the blocker class, last failing command/artifact, why another autonomous attempt would repeat, and the smallest manual action needed.'\n\t];\n\tconst sections = {\n\t\trunnerBasics,\n\t\ttokenDiscipline,\n\t\tdependencyBootstrap,\n\t\trepairLoop,\n\t\tqaPolicy,\n\t\tevidenceContract,\n\t\tfinalNotes\n\t};\n\tconst rules = [\n\t\t...runnerBasics,\n\t\t...tokenDiscipline,\n\t\t...dependencyBootstrap,\n\t\t...repairLoop,\n\t\t...qaPolicy,\n\t\t...evidenceContract,\n\t\t...finalNotes\n\t];\n\tconst promptLines = [\n\t\t`ResolveIO shared runner contract (${context}):`,\n\t\t...rules.map((rule) => `- ${rule}`)\n\t];\n\treturn {\n\t\tcontext,\n\t\tsections,\n\t\trules,\n\t\tpromptLines\n\t};\n}\n\nexport function buildResolveIORunnerPromptLines(options: ResolveIORunnerBasicsOptions = {}): string[] {\n\treturn buildResolveIORunnerContract(options).promptLines;\n}\n\nexport function buildResolveIORunnerPromptBundle(input: ResolveIORunnerPromptInput = {}): ResolveIORunnerPromptBundle {\n\tconst contract = buildResolveIORunnerContract(input);\n\tconst maxTextChars = normalizePositiveInteger(input.maxTextChars, 900, 160, 2400);\n\tconst objective = normalizeTextLine(input.objective, maxTextChars)\n\t\t|| 'Complete the requested ResolveIO runner task with minimal, verified changes.';\n\tconst priorSummary = normalizeTextLine(input.priorSummary, maxTextChars);\n\tconst latestFailure = normalizeTextLine(input.latestFailure, maxTextChars);\n\tconst blockers = normalizeTextList(input.blockers, normalizePositiveInteger(input.maxBlockers, 5, 1, 12), maxTextChars);\n\tconst relevantFiles = normalizeTextList(input.relevantFiles, normalizePositiveInteger(input.maxFiles, 12, 1, 30), 260);\n\tconst evidence = normalizeTextList(input.evidence, normalizePositiveInteger(input.maxEvidence, 8, 1, 20), maxTextChars);\n\tconst contextLines = [\n\t\t`Objective: ${objective}`,\n\t\t...(priorSummary ? [`Prior summary: ${priorSummary}`] : []),\n\t\t...(latestFailure ? [`Latest failure: ${latestFailure}`] : []),\n\t\t...(blockers.length ? ['Active blockers:', ...blockers.map((line) => `- ${line}`)] : []),\n\t\t...(relevantFiles.length ? ['Relevant files:', ...relevantFiles.map((line) => `- ${line}`)] : []),\n\t\t...(evidence.length ? ['Known evidence:', ...evidence.map((line) => `- ${line}`)] : [])\n\t];\n\tconst repairLines = blockers.length\n\t\t? [\n\t\t\t'Mandatory repair contract:',\n\t\t\t'- Address each active blocker before unrelated work.',\n\t\t\t'- For each blocker, mark resolved, proven false, or blocked.',\n\t\t\t'- Attach code, data, command, browser, screenshot, or trace proof for each blocker.',\n\t\t\t'- If a blocker repeats with no meaningful diff/evidence change, park instead of starting another broad attempt.'\n\t\t]\n\t\t: [];\n\tconst fullPromptLines = [\n\t\t...contract.promptLines,\n\t\t'',\n\t\t'Runner task context:',\n\t\t...contextLines,\n\t\t...(repairLines.length ? ['', ...repairLines] : [])\n\t];\n\treturn {\n\t\t...contract,\n\t\tobjective,\n\t\tcontextLines,\n\t\trepairLines,\n\t\tfullPromptLines\n\t};\n}\n\nexport function buildResolveIORunnerRepairPromptLines(input: ResolveIORunnerPromptInput = {}): string[] {\n\treturn buildResolveIORunnerPromptBundle(input).repairLines;\n}\n"]}
|