@exellix/ai-tasks 8.4.3 → 8.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/.docs/ai-tasks-model-profile-aliases-7x.md +27 -5
  2. package/CHANGELOG.md +16 -0
  3. package/README.md +5 -4
  4. package/RUNTASK_REQUEST.md +1 -1
  5. package/dist/core/task-sdk.d.ts.map +1 -1
  6. package/dist/core/task-sdk.js +56 -29
  7. package/dist/core/task-sdk.js.map +1 -1
  8. package/dist/errors/runTaskExecutionError.d.ts +1 -1
  9. package/dist/errors/runTaskExecutionError.d.ts.map +1 -1
  10. package/dist/errors/runTaskExecutionError.js +4 -1
  11. package/dist/errors/runTaskExecutionError.js.map +1 -1
  12. package/dist/errors/runTaskModelResolutionError.d.ts +39 -0
  13. package/dist/errors/runTaskModelResolutionError.d.ts.map +1 -0
  14. package/dist/errors/runTaskModelResolutionError.js +92 -0
  15. package/dist/errors/runTaskModelResolutionError.js.map +1 -0
  16. package/dist/execution-strategies/constants.d.ts +11 -4
  17. package/dist/execution-strategies/constants.d.ts.map +1 -1
  18. package/dist/execution-strategies/constants.js +11 -4
  19. package/dist/execution-strategies/constants.js.map +1 -1
  20. package/dist/execution-strategies/executionStrategyCatalogMetadata.d.ts +6 -3
  21. package/dist/execution-strategies/executionStrategyCatalogMetadata.d.ts.map +1 -1
  22. package/dist/execution-strategies/executionStrategyCatalogMetadata.js +36 -5
  23. package/dist/execution-strategies/executionStrategyCatalogMetadata.js.map +1 -1
  24. package/dist/execution-strategies/executionStrategyRequestPayload.d.ts +19 -0
  25. package/dist/execution-strategies/executionStrategyRequestPayload.d.ts.map +1 -0
  26. package/dist/execution-strategies/executionStrategyRequestPayload.js +21 -0
  27. package/dist/execution-strategies/executionStrategyRequestPayload.js.map +1 -0
  28. package/dist/execution-strategies/runExecutionStrategyViaXynthesis.d.ts +35 -0
  29. package/dist/execution-strategies/runExecutionStrategyViaXynthesis.d.ts.map +1 -0
  30. package/dist/execution-strategies/runExecutionStrategyViaXynthesis.js +129 -0
  31. package/dist/execution-strategies/runExecutionStrategyViaXynthesis.js.map +1 -0
  32. package/dist/index.d.ts +16 -4
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +15 -4
  35. package/dist/index.js.map +1 -1
  36. package/dist/internal/resolveLlmCallForXynthesis.d.ts.map +1 -1
  37. package/dist/internal/resolveLlmCallForXynthesis.js +6 -0
  38. package/dist/internal/resolveLlmCallForXynthesis.js.map +1 -1
  39. package/dist/internal/runPostStepLlmCall.d.ts.map +1 -1
  40. package/dist/internal/runPostStepLlmCall.js +4 -1
  41. package/dist/internal/runPostStepLlmCall.js.map +1 -1
  42. package/dist/logxer/aiTasksDiagnosticCodes.d.ts +3 -0
  43. package/dist/logxer/aiTasksDiagnosticCodes.d.ts.map +1 -1
  44. package/dist/logxer/aiTasksDiagnosticCodes.js +3 -0
  45. package/dist/logxer/aiTasksDiagnosticCodes.js.map +1 -1
  46. package/dist/observability/classifyRunTaskFailure.d.ts +1 -1
  47. package/dist/observability/classifyRunTaskFailure.d.ts.map +1 -1
  48. package/dist/observability/classifyRunTaskFailure.js +12 -0
  49. package/dist/observability/classifyRunTaskFailure.js.map +1 -1
  50. package/dist/observability/logRunTaskFailure.d.ts.map +1 -1
  51. package/dist/observability/logRunTaskFailure.js +26 -8
  52. package/dist/observability/logRunTaskFailure.js.map +1 -1
  53. package/dist/planWebScopeQuestions/index.d.ts +4 -8
  54. package/dist/planWebScopeQuestions/index.d.ts.map +1 -1
  55. package/dist/planWebScopeQuestions/index.js +114 -149
  56. package/dist/planWebScopeQuestions/index.js.map +1 -1
  57. package/dist/post-steps/audit/auditChecklistFuncxEnvelope.d.ts +57 -0
  58. package/dist/post-steps/audit/auditChecklistFuncxEnvelope.d.ts.map +1 -0
  59. package/dist/post-steps/audit/auditChecklistFuncxEnvelope.js +80 -0
  60. package/dist/post-steps/audit/auditChecklistFuncxEnvelope.js.map +1 -0
  61. package/dist/task-strategies/canonicalInputExecutionStrategies.d.ts +21 -21
  62. package/dist/task-strategies/canonicalInputExecutionStrategies.js +12 -12
  63. package/dist/task-strategies/canonicalInputExecutionStrategies.js.map +1 -1
  64. package/dist/task-strategies/normalize.d.ts.map +1 -1
  65. package/dist/task-strategies/normalize.js +3 -0
  66. package/dist/task-strategies/normalize.js.map +1 -1
  67. package/dist/task-strategies/types.d.ts +4 -2
  68. package/dist/task-strategies/types.d.ts.map +1 -1
  69. package/dist/types/llmCall.d.ts +1 -1
  70. package/dist/types/llmCall.d.ts.map +1 -1
  71. package/dist/types/llmCall.js.map +1 -1
  72. package/dist/utils/concreteModelId.d.ts.map +1 -1
  73. package/dist/utils/concreteModelId.js +4 -1
  74. package/dist/utils/concreteModelId.js.map +1 -1
  75. package/dist/utils/resolveAiProfileModel.d.ts +6 -1
  76. package/dist/utils/resolveAiProfileModel.d.ts.map +1 -1
  77. package/dist/utils/resolveAiProfileModel.js +11 -2
  78. package/dist/utils/resolveAiProfileModel.js.map +1 -1
  79. package/dist/utils/resolveRunTaskModelReferences.d.ts.map +1 -1
  80. package/dist/utils/resolveRunTaskModelReferences.js +93 -30
  81. package/dist/utils/resolveRunTaskModelReferences.js.map +1 -1
  82. package/dist/validation/helpers.js +1 -1
  83. package/dist/validation/helpers.js.map +1 -1
  84. package/documenations/funcx-catalog-hosting-checklist.md +2 -2
  85. package/documenations/funcx-scoping-integration-gaps.md +8 -6
  86. package/documenations/upstream-feature-requests/README.md +10 -0
  87. package/documenations/upstream-feature-requests/funcx-generic-xynthesis-hosting.md +294 -0
  88. package/documenations/upstream-feature-requests/funcx-pre-post-sidekick-actions.md +301 -0
  89. package/documenations/upstream-feature-requests/xynthesis-execution-strategies-option-a.md +637 -0
  90. package/package.json +2 -10
@@ -0,0 +1,294 @@
1
+ # `@x12i/funcx` — generic envelope hosting for xynthesis-domain capabilities
2
+
3
+ **Filed by:** `@exellix/ai-tasks`
4
+ **Consumers:** `@exellix/xynthesis` (LLM hops), `@exellix/ai-tasks` (envelope builders + adapters)
5
+ **Out of scope:** `@exellix/ai-skills` MAIN gateway prompts (skill templates, `instructions` / `prompt` on `RunTaskRequest`)
6
+
7
+ **Related:**
8
+
9
+ - [`funcx-scoping-integration-gaps.md`](../funcx-scoping-integration-gaps.md) — scoping `ask()` gaps + §6 execution-strategy wire contracts
10
+ - [`funcx-catalog-hosting-checklist.md`](../funcx-catalog-hosting-checklist.md) — deploy checklist for `run()` resolution
11
+ - [`xynthesis-execution-strategies-option-a.md`](./xynthesis-execution-strategies-option-a.md) — **shipped** xynthesis 4.4 sidekick actions (interim: disk templates + `FuncxInvoker.ask`)
12
+ - Envelope builders (stable): [`genericExecutionFuncxEnvelope.ts`](../../src/execution-strategies/genericExecutionFuncxEnvelope.ts)
13
+ - Xynthesis templates today (duplicate host): `xynthesis/templates/execution-plan/`, `execution-evaluate-result/`, `plan-web-scope-questions/`
14
+
15
+ ---
16
+
17
+ ## 0. Target architecture
18
+
19
+ For every **xynthesis-domain** LLM capability (not ai-skills MAIN):
20
+
21
+ 1. **Wire:** `GenericExecutionEnvelope` — `goal`, `input`, `context`, optional `result`, `args`, `attribution`.
22
+ 2. **Prompt host:** FuncX function (built-in or Catalox content) — templates read envelope fields and **`args`** for per-template customization (guidelines, caps, variant keys).
23
+ 3. **Orchestration:** `@exellix/xynthesis` owns model resolution, Optimixer / `outputExpectation`, JSON parse, Activix, `InvokeAttemptSummary` — ideally by calling **`run(functionId, envelope, options)`** instead of re-rendering duplicate templates and calling `Client.ask` directly.
24
+ 4. **ai-tasks:** Builds envelopes only; merges adapted JSON into `RunTaskRequest` (planner/optimizer/web-scope). No inline system prompts for these paths.
25
+
26
+ **Today (gap):** FuncX already ships built-ins `execution-plan`, `execution-evaluate-result`, `research-plan-questions` with envelope-shaped I/O, but **xynthesis 4.4 re-hosts prompts** under sidekick templates and uses `executeXynthesisAction` + `FuncxInvoker.ask`. **Post-steps and AI scoping** still use **caller-built** `systemPrompt` / `userPrompt` strings in ai-tasks (partially duplicated vs xynthesis `templates/audit`, `templates/fix`).
27
+
28
+ ---
29
+
30
+ ## 1. Audit — where instructions live
31
+
32
+ | Capability | Prompt / instructions today | Wire today | Generic envelope? | FuncX `run()`? |
33
+ |------------|----------------------------|------------|-------------------|----------------|
34
+ | **execution-plan** | `xynthesis/templates/execution-plan/*` + `buildExecutionStrategyPrompts` | xynthesis `RunExecutionPlanRequest` | Yes (ai-tasks builds payload) | Built-in exists; **not used** by xynthesis 4.4 |
35
+ | **execution-evaluate-result** | Same pattern | xynthesis request + `result` | Yes | Built-in exists; **not used** |
36
+ | **plan-web-scope-questions** | Same pattern | `goal` / `input` / `context` / `args` | Yes | `research-plan-questions` built-in; **not used** |
37
+ | **synthesis (PRE)** | xynthesis `templates/synthesis/*` | `SidekickInput` + rendered skill text | **Sidekick envelope** (FR-PRE-POST) | **`pre/synthesize`** — **missing** |
38
+ | **post-audit** | **ai-tasks** `loadAuditTemplates` + `DEFAULT_SYSTEM` | Pre-built prompts → `executeXynthesisAction` | **Sidekick envelope** | **`post/audit-checklist`** — **missing** |
39
+ | **post-polish** | **ai-tasks** `loadPolishTemplates` + `DEFAULT_SYSTEM` | Pre-built prompts; Optimixer maps stage → `fix` | **Sidekick envelope** | **`post/fix`** — **missing** |
40
+ | **ai-scoping** | **Inline** `SCOPING_SYSTEM` in `runScopingCall.ts` | Pre-built prompts; no `sidekickAction` | **No** | **Missing** |
41
+ | **audit / fix / pick-best / craft-final** (xynthesis-native) | xynthesis `templates/{audit,fix,...}/*` | `runSidekickGatewayCall` when used | Sidekick envelope | **`post/*`** — **missing** (today: rendrix + `ask`) |
42
+
43
+ **Duplication risk:** xynthesis 4.4 execution-strategy templates and FuncX `content-seed` / Catalox prompts for the same three capabilities can drift unless one is canonical.
44
+
45
+ **ai-tasks still correct for:** envelope construction (`buildPlannerGenericPayload`, `buildOptimizerGenericPayload`, `buildResearchPlanQuestionsPayload`) and response adapters (`adaptExecutionPlanResult`, etc.) — keep even when xynthesis calls FuncX internally.
46
+
47
+ ---
48
+
49
+ ## 2. FuncX feature requests (tracker)
50
+
51
+ | FR id | Topic | Priority |
52
+ |-------|--------|----------|
53
+ | **FR-GEN-1** | Canonical **template context** from `GenericExecutionEnvelope` | P0 |
54
+ | **FR-GEN-2** | **`args` → template customization** contract (document + validate) | P0 |
55
+ | **FR-GEN-3** | **Output JSON schemas** aligned with ai-tasks adapters | P0 |
56
+ | **FR-GEN-4** | **`run()` + `RunOptions`** for model, timeout, `response_format`, attribution | P1 |
57
+ | **FR-GEN-5** | **`runGenericExecution`** helper (envelope → ask → parse → usage) for xynthesis | P1 |
58
+ | **FR-GEN-6** | **Post-step generic** functions (`post/audit`, `post/polish` or `xynthesis/audit`) | P1 |
59
+ | **FR-PRE-POST-*** | **Pre/post sidekick built-ins** + Catalox mapping — see [**funcx-pre-post-sidekick-actions.md**](./funcx-pre-post-sidekick-actions.md) | **P0** |
60
+ | **FR-GEN-7** | **AI scoping** generic function (`scoping/run` or `research/scope-content`) | P2 |
61
+ | **FR-GEN-8** | **`strategyArgs` vs `args`** on wire (or documented merge rule) | P1 |
62
+ | **FR-GEN-9** | **Catalox seed parity** with xynthesis 4.4 templates + CI diff | P1 |
63
+ | **FR-GEN-10** | **Deprecate** legacy `ai-tasks-plan-task` / `ai-tasks-optimizer-evaluate` ids | P2 |
64
+ | **FR-GEN-11** | **Sidekick-shaped** post-steps via envelope (audit checks in `context`) | P2 |
65
+ | **FR-GEN-12** | **Contract tests** package: envelope fixtures → expected adapter output | P1 |
66
+
67
+ §6 in [`funcx-scoping-integration-gaps.md`](../funcx-scoping-integration-gaps.md) remains the **adapter-level** contract for execution/research ids; this doc adds **hosting + template** requirements.
68
+
69
+ ---
70
+
71
+ ### FR-GEN-1 — Canonical template context from envelope
72
+
73
+ **Need:** Every generic execution/research built-in must render prompts from a **stable, documented** variable map derived from the envelope — not ad hoc TS string building in each consumer.
74
+
75
+ **Require FuncX built-ins / Catalox templates to expose at minimum:**
76
+
77
+ | Token / field | Source |
78
+ |---------------|--------|
79
+ | `goal` | `envelope.goal` (string, trimmed) |
80
+ | `input_json` | `JSON.stringify(envelope.input ?? null)` with documented max length + truncation suffix |
81
+ | `context_json` | `JSON.stringify(envelope.context ?? {})` — same truncation rules |
82
+ | `result_json` | Optimizer / evaluate only — `envelope.result` |
83
+ | `args_json` | `JSON.stringify(envelope.args ?? {})` |
84
+ | `iteration_index` | `envelope.args.iterationIndex` when present (stringified) |
85
+
86
+ **Ask:** Export `buildGenericExecutionTemplateContext(envelope): Record<string, string>` from `@x12i/funcx/functions` (or document it in `docs/migration-generic-execution.md`) so xynthesis can stop duplicating `executionStrategyPromptTemplate.ts` stringification.
87
+
88
+ **Acceptance:** xynthesis 4.4 templates and FuncX Catalox seeds use the **same** token names; one integration test compares rendered user prompt hashes for a golden fixture.
89
+
90
+ ---
91
+
92
+ ### FR-GEN-2 — `args` → template-level customization
93
+
94
+ **Need:** Strategy rows and hosts pass opaque knobs in `args` (minus `functionId`) that **templates** read without new function ids — e.g. `customGuidelines`, `maxQuestions`, `allowSkip`, `templateVariant`, `density`.
95
+
96
+ **Today (ai-tasks / xynthesis):**
97
+
98
+ - Planner/optimizer: `strategyArgs` forwarded separately in xynthesis; FuncX types only document `args`.
99
+ - Audit: `customAuditGuidelines` merged in ai-tasks `renderAuditSystem`, not in envelope.
100
+ - Web-scope: `args.maxQuestions`, `args.sourceType`, `args.allowSkip`.
101
+
102
+ **Ask:**
103
+
104
+ 1. Document **reserved vs extension** keys in `args` per function id (JSON Schema `args` sub-schemas in `fx/*/meta.json`).
105
+ 2. Support **nested template overrides** via convention, e.g. `args.promptOverrides.systemSuffix`, `args.customGuidelines`, without breaking generic envelope validation.
106
+ 3. Optional: `args._templateProfile: "strict" | "lenient"` to select Catalox template variant.
107
+
108
+ **Acceptance:** Changing only `args.customGuidelines` in a fixture changes the rendered system prompt in tests; no TypeScript change in consumers.
109
+
110
+ ---
111
+
112
+ ### FR-GEN-3 — Output JSON schemas aligned with ai-tasks adapters
113
+
114
+ **Need:** Built-in outputs must match what [`adaptExecutionPlanResult`](../../src/execution-strategies/genericExecutionFuncxEnvelope.ts), [`adaptEvaluateResultResponse`](../../src/execution-strategies/genericExecutionFuncxEnvelope.ts), and [`adaptResearchPlanQuestionsResult`](../../src/execution-strategies/genericExecutionFuncxEnvelope.ts) expect.
115
+
116
+ **Planner (`execution-plan` / `execution/plan`):**
117
+ `plan?`, `instructions?`, `steps[]`, `assumptions[]`, `missingInputs[]`, optional `prompt`, `variables`, `templateTokens` (top-level or under `metadata`).
118
+
119
+ **Optimizer (`execution-evaluate-result`):**
120
+ `satisfied` (boolean), `feedback?`, `suggestedChanges[]`, `issues[]`, optional `variables`, `templateTokens`, `metadata`.
121
+
122
+ **Research (`research-plan-questions`):**
123
+ `questions[]` with `question`, optional `reason`, `confidence`; optional `skipped`, `reasonCodes`.
124
+
125
+ **Ask:** Publish machine-readable schemas next to built-ins; version with semver when fields change. Include **`getRunJsonResult`** normalization examples in docs.
126
+
127
+ **Gap vs xynthesis 4.4 parsers:** If FuncX adds fields, xynthesis `parseExecutionStrategyPayload` should defer to FuncX schema or share one JSON Schema file.
128
+
129
+ ---
130
+
131
+ ### FR-GEN-4 — `run()` + `RunOptions` for orchestrator controls
132
+
133
+ **Need:** `@exellix/xynthesis` must pass **resolved model**, timeout, temperature, `response_format: json_object`, and merged **attribution** without re-implementing `ask()` options.
134
+
135
+ **Ask:**
136
+
137
+ - Extend `RunOptions` (or documented overload) with: `model`, `timeoutMs`, `temperature`, `topP`, `reasoningEffort`, `responseFormat`, `maxTokens` / completion cap hint.
138
+ - Built-ins call `buildAskAttribution(implFunctionId, envelope)` internally when `attribution` is present.
139
+ - Return shape includes **`usage`** and fields xynthesis maps to `InvokeAttemptSummary` (or document mapping table).
140
+
141
+ **Acceptance:** xynthesis `invokeExecutionStrategyAction` can replace `executeXynthesisAction` + manual prompts with `run(FUNCX_EXECUTION_PLAN_FUNCTION_ID, payload, options)` while preserving observability parity.
142
+
143
+ ---
144
+
145
+ ### FR-GEN-5 — `runGenericExecution` helper for embedders
146
+
147
+ **Need:** Thin API for packages that already own parse/Activix but should not fork prompt assembly.
148
+
149
+ **Proposed export (`@x12i/funcx/functions`):**
150
+
151
+ ```ts
152
+ runGenericExecution(opts: {
153
+ functionId: string;
154
+ envelope: GenericExecutionEnvelope;
155
+ client?: Client;
156
+ runOptions?: RunOptions;
157
+ }): Promise<{ value: unknown; usage?: Usage; model?: string; raw?: unknown }>;
158
+ ```
159
+
160
+ **Behavior:** Resolve content → render templates from FR-GEN-1 context → `ask` / `askJson` → validate against function output schema → return parsed object.
161
+
162
+ **Acceptance:** xynthesis deletes duplicate template render path when this ships; tests use `createAskMock` at FuncX boundary only.
163
+
164
+ ---
165
+
166
+ ### FR-GEN-6 — Post-step generic functions (audit, polish)
167
+
168
+ **Need:** Remove ai-tasks **inline** `DEFAULT_SYSTEM` and duplicate template trees; use envelope + FuncX templates.
169
+
170
+ **Proposed ids:**
171
+
172
+ | Capability | Suggested `functionId` | Envelope highlights |
173
+ |------------|------------------------|---------------------|
174
+ | Audit evaluator | `post/audit` or `xynthesis/audit` | `goal`: audit objective; `input`: output under test; `context`: checks, synthesis excerpt, pass metadata; `args`: `customGuidelines`, `passNumber` |
175
+ | Polish | `post/polish` or `xynthesis/fix` | `input`: draft output; `context`: checklist, prior pass notes; `args`: `customGuidelines` |
176
+
177
+ **Output:** Audit — markdown or structured sections; Polish — JSON `{ polishedOutput, changeNotes }` per current ai-tasks parsers.
178
+
179
+ **Acceptance:** `runAuditCall` / `runPolishCall` build envelope + `run()`; xynthesis `executeXynthesisAction` only for transport if still needed, or xynthesis wraps FR-GEN-5.
180
+
181
+ ---
182
+
183
+ ### FR-GEN-7 — AI scoping generic function
184
+
185
+ **Need:** Replace `SCOPING_SYSTEM` constant in [`runScopingCall.ts`](../../src/aiScoping/runScopingCall.ts).
186
+
187
+ **Proposed id:** `scoping/run` or `research/scope-content`
188
+
189
+ **Envelope:**
190
+
191
+ - `goal`: scoping directive (from caller `instructions`)
192
+ - `input`: `{ sourceContent: string }` or raw string policy documented
193
+ - `args`: `outputExpectation` hints, `maxOutputLength`
194
+
195
+ **Output:** Plain text scoped result (no markdown / fences) — document in schema.
196
+
197
+ **Acceptance:** No inline system string in ai-tasks; FuncX template owns behavior.
198
+
199
+ ---
200
+
201
+ ### FR-GEN-8 — `strategyArgs` vs `args` on wire
202
+
203
+ **Need:** ai-tasks execution strategies pass catalog row `args` (minus `functionId`) while xynthesis 4.4 also accepts `strategyArgs` on the request object.
204
+
205
+ **Options (pick one in FuncX):**
206
+
207
+ 1. **Merge rule:** At `run()` entry, `effectiveArgs = { ...envelope.args, ...envelope.strategyArgs }` if `strategyArgs` is added to `GenericExecutionEnvelope`.
208
+ 2. **Document:** Consumers must fold `strategyArgs` into `args` before `run()`; export `mergeStrategyArgs(envelope)` helper.
209
+
210
+ **Ask:** Update `GenericExecutionEnvelope` TypeScript type and `genericExecutionEnvelopeJsonSchema` if `strategyArgs` becomes first-class.
211
+
212
+ ---
213
+
214
+ ### FR-GEN-9 — Catalox seed parity with xynthesis 4.4
215
+
216
+ **Need:** Single canonical prompt source.
217
+
218
+ **Ask:**
219
+
220
+ 1. Diff `xynthesis/templates/execution-*` and `plan-web-scope-questions` against `content-seed/functions/genericExecutionResearch.seed.json` (or per-function seeds).
221
+ 2. CI job fails on drift unless bumping `contentVersion`.
222
+ 3. Document sync procedure: xynthesis exports → FuncX seed import (or FuncX seed → xynthesis pull).
223
+
224
+ **Acceptance:** Product can disable xynthesis disk templates when Catalox actions enabled (`isCataloxActionsEnabled`) without behavior change.
225
+
226
+ ---
227
+
228
+ ### FR-GEN-10 — Deprecate legacy ai-tasks function ids
229
+
230
+ **Need:** FuncX registry still lists `ai-tasks-plan-task`, `ai-tasks-optimizer-evaluate` alongside `execution-plan`, `execution-evaluate-result`.
231
+
232
+ **Ask:** Mark legacy ids deprecated in meta; route aliases to generic built-ins; remove from seed catalog after one major.
233
+
234
+ ---
235
+
236
+ ### FR-GEN-11 — Sidekick-shaped post-steps via envelope (optional)
237
+
238
+ **Need:** Audit today uses rich `SidekickInput` (checks array, material blocks). Migrating to envelope should not lose structure.
239
+
240
+ **Ask:** Define `context.audit` sub-schema (checks, outputText, synthesisSummary, …) in FR-GEN-6 meta so templates stay declarative.
241
+
242
+ ---
243
+
244
+ ### FR-GEN-12 — Contract tests for adapters
245
+
246
+ **Need:** Prevent drift between FuncX built-in output and ai-tasks adapters.
247
+
248
+ **Ask:** Ship `test/fixtures/generic-execution/*.json` in `@x12i/funcx` run in CI; ai-tasks imports fixtures or duplicates with cross-package version pin.
249
+
250
+ ---
251
+
252
+ ## 3. Recommended convergence path
253
+
254
+ ```mermaid
255
+ flowchart LR
256
+ subgraph ai_tasks
257
+ A[buildPlannerGenericPayload]
258
+ end
259
+ subgraph xynthesis
260
+ B[runExecutionPlan]
261
+ C{FR-GEN-5 shipped?}
262
+ end
263
+ subgraph funcx
264
+ D[run execution-plan]
265
+ E[Catalox templates + args]
266
+ end
267
+ A --> B
268
+ B --> C
269
+ C -->|yes| D
270
+ C -->|interim 4.4| F[disk templates + ask]
271
+ D --> E
272
+ F --> E
273
+ ```
274
+
275
+ 1. **FuncX:** Implement FR-GEN-1–3, FR-GEN-9 (canonical prompts + schemas).
276
+ 2. **FuncX:** FR-GEN-4–5 so xynthesis can call `run()` without duplicate `executionStrategyPromptTemplate.ts`.
277
+ 3. **xynthesis:** Follow-up FR (separate doc) — switch `invokeExecutionStrategyAction` to FuncX `run()`; keep parsers/adapters.
278
+ 4. **ai-tasks:** FR-GEN-6–7 for audit/polish/scoping; stop shipping `DEFAULT_SYSTEM` strings.
279
+ 5. **Docs:** Update [`funcx-catalog-hosting-checklist.md`](../funcx-catalog-hosting-checklist.md) — built-ins are canonical; Catalox overrides via `args`.
280
+
281
+ ---
282
+
283
+ ## 4. Non-goals
284
+
285
+ - Changing ai-skills MAIN `instructions` / `prompt` contract.
286
+ - Moving synthesis PRE-step template **cores** (`{{core:analysis}}`) into FuncX — cores stay rendrix/ai-skills; FuncX hosts the **synthesis action** via `pre/synthesize` (see [funcx-pre-post-sidekick-actions.md](./funcx-pre-post-sidekick-actions.md)).
287
+ - Forcing ai-tasks to call `@x12i/funcx` directly again for execution strategies (xynthesis remains the facade after FR-GEN-5).
288
+
289
+ ---
290
+
291
+ ## 5. Version note
292
+
293
+ - **@x12i/funcx** ≥ **4.2.0** (ai-tasks dep): `FUNCX_*_FUNCTION_ID`, `genericExecutionEnvelopeJsonSchema`, `buildAskAttribution`, `getRunJsonResult`.
294
+ - Built-in ids in registry: `execution-plan`, `execution-evaluate-result`, `research-plan-questions` (slash aliases normalize per README).
@@ -0,0 +1,301 @@
1
+ # `@x12i/funcx` — built-in functions for xynthesis **pre-actions** and **post-actions**
2
+
3
+ **Filed by:** `@exellix/ai-tasks` + `@exellix/xynthesis`
4
+ **Blocks:** Catalox-only sidekick path (`runXynthesisAiAction`), ai-tasks audit/polish migration off inline templates
5
+ **Related:** [funcx-generic-xynthesis-hosting.md](./funcx-generic-xynthesis-hosting.md), [funcx-catalog-hosting-checklist.md](../funcx-catalog-hosting-checklist.md)
6
+
7
+ ---
8
+
9
+ ## 0. Problem
10
+
11
+ Today xynthesis **pre-actions** (synthesis) and **post-actions** (audit, fix, pick-best, craft-final) load prompts from:
12
+
13
+ 1. On-disk `xynthesis/templates/{actionType}/`, or
14
+ 2. Catalox catalogs `pre-actions` / `post-actions` (same template bodies, seeded from disk).
15
+
16
+ The LLM hop uses **`FuncxInvoker.ask(systemPrompt, userPrompt)`** — a **transport-only** use of FuncX. Prompt text is assembled in xynthesis (`sidekickPromptTemplate.ts` + rendrix), **not** resolved from a FuncX **function id** via `run(functionId, envelope)`.
17
+
18
+ **ai-tasks** often bypasses even that path: it loads **its own** audit/polish templates and calls `executeXynthesisAction` with pre-built prompts.
19
+
20
+ **Target:** Each sidekick action has a **first-class FuncX function** (like `execution/plan`). xynthesis calls `run(functionId, envelope, runOptions)`; Catalox `pre-actions` / `post-actions` items **reference** the same `functionId` for content overrides, not duplicate template hosting.
21
+
22
+ ---
23
+
24
+ ## 1. Canonical mapping (FuncX ↔ Catalox ↔ sidekick)
25
+
26
+ | Phase | Sidekick `actionType` | Catalox catalog | Catalox item id | Proposed FuncX `functionId` | Hyphen alias |
27
+ |-------|----------------------|-----------------|-----------------|----------------------------|--------------|
28
+ | PRE | `synthesis` | `pre-actions` | `synthesis` | `pre/synthesize` | `pre-synthesize` |
29
+ | PRE | `execution-plan` | `pre-actions` | `execution-plan` | `execution/plan` | `execution-plan` |
30
+ | PRE | `plan-web-scope-questions` | `pre-actions` | `plan-web-scope-questions` | `research/plan-questions` | `research-plan-questions` |
31
+ | POST | `audit` | `post-actions` | `audit` | `post/audit` | `post-audit` |
32
+ | POST | `fix` | `post-actions` | `fix` | `post/fix` | `post-fix` |
33
+ | POST | `pick-best` | `post-actions` | `pick-best` | `post/pick-best` | `post-pick-best` |
34
+ | POST | `craft-final` | `post-actions` | `craft-final` | `post/craft-final` | `post-craft-final` |
35
+ | POST | `execution-evaluate-result` | `post-actions` | `execution-evaluate-result` | `execution/evaluate-result` | `execution-evaluate-result` |
36
+
37
+ **ai-tasks pipeline audit (weighted checks, markdown output)** — separate from sidekick JSON audit until unified:
38
+
39
+ | Capability | Proposed FuncX id | Catalox (optional) |
40
+ |------------|-------------------|-------------------|
41
+ | Checklist audit evaluator | `post/audit-checklist` | `post-actions` item `audit-checklist` |
42
+ | Audit-cycle synthesis merge | `post/audit-merge` | `post-actions` item `audit-merge` or reuse `pre/synthesize` with `args.profile: "audit-merge"` |
43
+
44
+ Constants and envelope builders live in xynthesis: `src/catalog/sidekickFuncxCatalogMap.ts`, `src/sidekickFuncxEnvelope.ts`.
45
+
46
+ ---
47
+
48
+ ## 2. Wire contract — sidekick generic envelope
49
+
50
+ Extend (or sibling-type) **`GenericExecutionEnvelope`** for sidekick actions:
51
+
52
+ ```ts
53
+ type SidekickGenericEnvelope = {
54
+ /** Directive: question / objective / instruction (maps to SidekickInput.task). */
55
+ goal: string;
56
+ /** Action-specific payload (see §3 per function). */
57
+ input: Record<string, unknown>;
58
+ /** Shared sidekick context. */
59
+ context: {
60
+ templateCores: string[];
61
+ taskType?: string;
62
+ metadata?: Record<string, unknown>;
63
+ /** Optimizer-only / evaluate-only fields when applicable. */
64
+ result?: unknown;
65
+ iterationIndex?: number;
66
+ };
67
+ /** Template customization — NOT merged into LLM attribution tags by default. */
68
+ args?: {
69
+ templateMode?: "structured" | "markdown";
70
+ customGuidelines?: string;
71
+ synthesisPromptOverride?: string;
72
+ /** Checklist audit: passNumber, cycle, maxCycles, … */
73
+ [key: string]: unknown;
74
+ };
75
+ attribution?: GenericFuncxAttribution;
76
+ };
77
+ ```
78
+
79
+ **Template context tokens** (FR-GEN-1 superset) — FuncX must render from envelope, matching xynthesis rendrix vars today:
80
+
81
+ | Token | Envelope source |
82
+ |-------|-----------------|
83
+ | `task`, `question` | `goal` (both aliases for synthesis compat) |
84
+ | `local_raw` | `input.localRaw` stringified |
85
+ | `supporting_raw` | `input.supportingRaw` stringified |
86
+ | `rendered_downstream_instructions` | `input.renderedInstructions` |
87
+ | `rendered_downstream_prompt` | `input.renderedPrompt` |
88
+ | `ai_output` | `input.aiOutput` |
89
+ | `used_instructions` | `input.usedInstructions` |
90
+ | `used_prompt` | `input.usedPrompt` |
91
+ | `prior_audit_json` | `JSON.stringify(input.priorAudit)` |
92
+ | `candidates_json` | `JSON.stringify(input.candidates)` |
93
+ | `prior_context` | `input.priorContext` |
94
+ | `metadata_json` | `JSON.stringify(context.metadata ?? {})` |
95
+ | `template_cores_json` | `JSON.stringify(context.templateCores)` |
96
+ | `goal`, `input_json`, `context_json`, `args_json` | FR-GEN-1 generic tokens (execution-strategy family) |
97
+
98
+ **Ask (FuncX):** export `buildSidekickTemplateContext(envelope): Record<string, string>` alongside `buildGenericExecutionTemplateContext`.
99
+
100
+ ---
101
+
102
+ ## 3. Per-function specifications
103
+
104
+ ### FR-PRE-1 — `pre/synthesize` (PRE synthesis)
105
+
106
+ **Canonical content:** `xynthesis/templates/synthesis/system-structured.md` + `user-structured.md` (and markdown variants).
107
+
108
+ **Envelope `input`:**
109
+
110
+ | Field | Type | Required |
111
+ |-------|------|----------|
112
+ | `localRaw` | any | no |
113
+ | `supportingRaw` | any | no |
114
+ | `renderedInstructions` | string | no |
115
+ | `renderedPrompt` | string | no |
116
+
117
+ **Output JSON** (matches `parseAndValidateSynthesizedPromptPayload` / `SynthesisPayload`):
118
+
119
+ - `templateCores`, `task`, `synthesized` (`SynthesizedContext`), optional `notes`, `unknowns`, `assumptions`
120
+
121
+ **`args`:** `templateMode`, `customGuidelines`, `synthesisPromptOverride`, `maxItemsPerSide`, `maxItemContentChars`
122
+
123
+ **Response format:** `json_object`
124
+
125
+ ---
126
+
127
+ ### FR-POST-1 — `post/audit` (sidekick JSON audit)
128
+
129
+ **Canonical content:** `xynthesis/templates/audit/*`
130
+
131
+ **Envelope `input`:**
132
+
133
+ | Field | Type | Required |
134
+ |-------|------|----------|
135
+ | `aiOutput` | string | yes |
136
+ | `usedInstructions` | string | no |
137
+ | `usedPrompt` | string | no |
138
+
139
+ **Output JSON** (matches `parseAuditPayload`):
140
+
141
+ - `verdict`: `"pass" | "fail" | "mixed"`
142
+ - `findings[]`: `{ id, label, content, severity? }`
143
+ - plus sidekick base fields (`notes`, `unknowns`, `assumptions`, …)
144
+
145
+ ---
146
+
147
+ ### FR-POST-2 — `post/audit-checklist` (ai-tasks weighted audit)
148
+
149
+ **Canonical content:** migrate from ai-tasks `templates/post-steps/audit/` (Handlebars → FuncX templates with same variables).
150
+
151
+ **Envelope `input`:**
152
+
153
+ | Field | Type | Required |
154
+ |-------|------|----------|
155
+ | `candidateOutput` | string | yes |
156
+ | `originalInput` | string | yes |
157
+ | `promptContext` | string | no |
158
+ | `mustChecks` | `{ check, weight }[]` | yes |
159
+ | `shouldChecks` | `{ check, weight }[]` | yes |
160
+ | `previousFeedback` | string | no |
161
+
162
+ **Output:** structured markdown (`### Checks`, `### Overall feedback`) — parsed by ai-tasks `parseAuditOutputFromMarkdown` until FuncX ships JSON schema variant.
163
+
164
+ **`args`:** `customAuditGuidelines`, `passNumber`, `cycle`, `maxCycles`
165
+
166
+ ---
167
+
168
+ ### FR-POST-3 — `post/fix` (polish / fix)
169
+
170
+ **Canonical content:** `xynthesis/templates/fix/*`
171
+
172
+ **Envelope `input`:** `aiOutput`, `usedInstructions?`, `usedPrompt?`, `priorAudit?` (AuditPayload)
173
+
174
+ **Output JSON:** `fixes[]` with `{ id, label, corrected, rationale? }` per `parseFixPayload`
175
+
176
+ ---
177
+
178
+ ### FR-POST-4 — `post/pick-best`
179
+
180
+ **Envelope `input`:** `candidates[]` (`{ id, content }`), `usedInstructions?`
181
+
182
+ **Output JSON:** `selected`, `rankings[]` per `parsePickBestPayload`
183
+
184
+ ---
185
+
186
+ ### FR-POST-5 — `post/craft-final`
187
+
188
+ **Envelope `input`:** `aiOutput`, `usedInstructions?`, `usedPrompt?`, `priorContext?`
189
+
190
+ **Output JSON:** per `parseCraftFinalPayload` (`finalOutput`, `rationale?`, …)
191
+
192
+ ---
193
+
194
+ ### FR-PRE-POST-6 — Execution-strategy ids (already exist — wire only)
195
+
196
+ **No new FuncX content required** if seeds match xynthesis templates (FR-GEN-9). xynthesis must **stop** re-rendering `executionStrategyPromptTemplate.ts` and call:
197
+
198
+ - `run("execution/plan", envelope)`
199
+ - `run("execution/evaluate-result", envelope)`
200
+ - `run("research/plan-questions", envelope)`
201
+
202
+ Catalox `pre-actions` / `post-actions` items for these actions gain `funcx.functionId` pointing at built-ins; templates in Catalox become **overrides** only.
203
+
204
+ ---
205
+
206
+ ## 4. Catalox catalog shape (consumer-side, after FuncX ships)
207
+
208
+ Each `XynthesisActionItem` in `pre-actions` / `post-actions` should include:
209
+
210
+ ```json
211
+ {
212
+ "actionType": "audit",
213
+ "funcx": {
214
+ "functionId": "post/audit",
215
+ "contentVersion": "1.0.0"
216
+ },
217
+ "templates": { "structured": { "system": "...", "user": "..." } },
218
+ "actionOutputDefaults": { ... },
219
+ "outputIntent": { ... }
220
+ }
221
+ ```
222
+
223
+ **Resolution order (xynthesis):**
224
+
225
+ 1. If `XYNTHESIS_FUNCX_SIDEKICK=1` (new flag): `run(item.funcx.functionId, buildSidekickGenericEnvelope(input), runOptions)`.
226
+ 2. Else if `XYNTHESIS_CATALOX_ACTIONS=1`: Catalox templates + rendrix (today).
227
+ 3. Else: disk templates (dev/tests).
228
+
229
+ When (1) is active, Catalox `templates` are **ignored for prompt text** unless FuncX catalog points at Catalox-hosted function content (FuncX content-seed parity).
230
+
231
+ ---
232
+
233
+ ## 5. FuncX package asks (summary tracker)
234
+
235
+ | FR id | Topic | Priority |
236
+ |-------|--------|----------|
237
+ | **FR-PRE-POST-1** | Register **`pre/synthesize`**, **`post/audit`**, **`post/fix`**, **`post/pick-best`**, **`post/craft-final`** built-ins | **P0** |
238
+ | **FR-PRE-POST-2** | Register **`post/audit-checklist`**, **`post/audit-merge`** for ai-tasks POST pipeline | **P1** |
239
+ | **FR-PRE-POST-3** | **`buildSidekickTemplateContext(envelope)`** export | **P0** |
240
+ | **FR-PRE-POST-4** | Output JSON schemas = xynthesis parser contracts (§3) | **P0** |
241
+ | **FR-PRE-POST-5** | `runSidekickGeneric(opts)` or extend FR-GEN-5 `runGenericExecution` for sidekick envelope | **P1** |
242
+ | **FR-PRE-POST-6** | Content-seed from `xynthesis/templates/{synthesis,audit,fix,...}` + CI drift vs Catalox | **P1** |
243
+ | **FR-PRE-POST-7** | Wire existing **`execution/*`** + **`research/plan-questions`** as canonical for pre/post catalog items (deprecate xynthesis duplicate render path) | **P0** |
244
+
245
+ Depends on [funcx-generic-xynthesis-hosting.md](./funcx-generic-xynthesis-hosting.md) **FR-GEN-1–5** for `RunOptions`, usage return shape, and generic template context.
246
+
247
+ ---
248
+
249
+ ## 6. Acceptance criteria (end-to-end)
250
+
251
+ - [ ] With `XYNTHESIS_FUNCX_SIDEKICK=1`, `runSidekickGatewayCall` never calls `loadSidekickTemplates` for registered actions; prompts come from FuncX `run()`.
252
+ - [ ] Catalox `pre-actions` / `post-actions` items include `funcx.functionId`; validation fails if missing when FuncX mode enabled.
253
+ - [ ] ai-tasks `runAuditPostStep` builds `post/audit-checklist` envelope — no `loadAuditTemplates` / `DEFAULT_SYSTEM`.
254
+ - [ ] ai-tasks PRE structured synthesis uses `pre/synthesize` via xynthesis (not local template load + `executeXynthesisAction`).
255
+ - [ ] Golden fixture: same envelope → FuncX rendered prompts hash-equal to current xynthesis rendrix output (FR-GEN-9 parity).
256
+ - [ ] `sidekickAction` on Activix / `InvokeAttemptSummary` records FuncX `functionId`, not only transport `ask`.
257
+
258
+ ---
259
+
260
+ ## 7. Convergence (mermaid)
261
+
262
+ ```mermaid
263
+ flowchart TB
264
+ subgraph ai_tasks
265
+ AT[buildSidekick envelope data]
266
+ end
267
+ subgraph xynthesis
268
+ XY[runSidekickGatewayCall / runXynthesisAiAction]
269
+ MAP[sidekickFuncxCatalogMap]
270
+ ENV[buildSidekickGenericEnvelope]
271
+ end
272
+ subgraph funcx
273
+ RUN["run(functionId, envelope)"]
274
+ TPL[Catalox / content-seed templates]
275
+ end
276
+ subgraph catalox
277
+ PRE[pre-actions catalog]
278
+ POST[post-actions catalog]
279
+ end
280
+ AT --> XY
281
+ XY --> MAP
282
+ MAP --> ENV
283
+ ENV --> RUN
284
+ RUN --> TPL
285
+ PRE -.->|funcx.functionId + optional override| MAP
286
+ POST -.->|funcx.functionId + optional override| MAP
287
+ ```
288
+
289
+ ---
290
+
291
+ ## 8. Non-goals
292
+
293
+ - ai-skills MAIN gateway (`instructions` / `prompt` on `RunTaskRequest`).
294
+ - Moving template **cores** (`{{core:analysis}}`) into FuncX — still rendrix/ai-skills concern; synthesis **input** may include pre-rendered downstream blocks only.
295
+
296
+ ---
297
+
298
+ ## 9. Version note
299
+
300
+ - **@x12i/funcx** ≥ **4.4.0** (xynthesis dep): `run`, `getRunJsonResult`, `GenericExecutionEnvelope`, `Client.ask`.
301
+ - New built-ins require FuncX release + content-seed; xynthesis gates behind **`XYNTHESIS_FUNCX_SIDEKICK=1`** until parity tests pass.