@xemahq/opencode-client 0.1.1
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/LICENSE +201 -0
- package/README.md +67 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/agent-registry.d.ts +3 -0
- package/dist/lib/agent-registry.d.ts.map +1 -0
- package/dist/lib/agent-registry.js +12 -0
- package/dist/lib/agent-registry.js.map +1 -0
- package/dist/lib/agents/agent-markdown-loader.d.ts +11 -0
- package/dist/lib/agents/agent-markdown-loader.d.ts.map +1 -0
- package/dist/lib/agents/agent-markdown-loader.js +194 -0
- package/dist/lib/agents/agent-markdown-loader.js.map +1 -0
- package/dist/lib/agents/index.d.ts +7 -0
- package/dist/lib/agents/index.d.ts.map +1 -0
- package/dist/lib/agents/index.js +25 -0
- package/dist/lib/agents/index.js.map +1 -0
- package/dist/lib/agents/registry.d.ts +7 -0
- package/dist/lib/agents/registry.d.ts.map +1 -0
- package/dist/lib/agents/registry.js +18 -0
- package/dist/lib/agents/registry.js.map +1 -0
- package/dist/lib/agents/types.d.ts +24 -0
- package/dist/lib/agents/types.d.ts.map +1 -0
- package/dist/lib/agents/types.js +11 -0
- package/dist/lib/agents/types.js.map +1 -0
- package/dist/lib/control-plane/agents-md-sections.d.ts +11 -0
- package/dist/lib/control-plane/agents-md-sections.d.ts.map +1 -0
- package/dist/lib/control-plane/agents-md-sections.js +367 -0
- package/dist/lib/control-plane/agents-md-sections.js.map +1 -0
- package/dist/lib/control-plane/index.d.ts +3 -0
- package/dist/lib/control-plane/index.d.ts.map +1 -0
- package/dist/lib/control-plane/index.js +6 -0
- package/dist/lib/control-plane/index.js.map +1 -0
- package/dist/lib/direct-llm-invoker.d.ts +11 -0
- package/dist/lib/direct-llm-invoker.d.ts.map +1 -0
- package/dist/lib/direct-llm-invoker.js +176 -0
- package/dist/lib/direct-llm-invoker.js.map +1 -0
- package/dist/lib/llm-registry-client.d.ts +4 -0
- package/dist/lib/llm-registry-client.d.ts.map +1 -0
- package/dist/lib/llm-registry-client.js +15 -0
- package/dist/lib/llm-registry-client.js.map +1 -0
- package/dist/lib/mcp/mcp-tool-catalog.d.ts +13 -0
- package/dist/lib/mcp/mcp-tool-catalog.d.ts.map +1 -0
- package/dist/lib/mcp/mcp-tool-catalog.js +3 -0
- package/dist/lib/mcp/mcp-tool-catalog.js.map +1 -0
- package/dist/lib/modes/direct-llm.provider.d.ts +11 -0
- package/dist/lib/modes/direct-llm.provider.d.ts.map +1 -0
- package/dist/lib/modes/direct-llm.provider.js +26 -0
- package/dist/lib/modes/direct-llm.provider.js.map +1 -0
- package/dist/lib/opencode-config.interface.d.ts +13 -0
- package/dist/lib/opencode-config.interface.d.ts.map +1 -0
- package/dist/lib/opencode-config.interface.js +5 -0
- package/dist/lib/opencode-config.interface.js.map +1 -0
- package/dist/lib/opencode-utils.d.ts +2 -0
- package/dist/lib/opencode-utils.d.ts.map +1 -0
- package/dist/lib/opencode-utils.js +10 -0
- package/dist/lib/opencode-utils.js.map +1 -0
- package/dist/lib/opencode.module.d.ts +15 -0
- package/dist/lib/opencode.module.d.ts.map +1 -0
- package/dist/lib/opencode.module.js +46 -0
- package/dist/lib/opencode.module.js.map +1 -0
- package/dist/lib/opencode.service.d.ts +11 -0
- package/dist/lib/opencode.service.d.ts.map +1 -0
- package/dist/lib/opencode.service.js +53 -0
- package/dist/lib/opencode.service.js.map +1 -0
- package/dist/lib/opencode.types.d.ts +77 -0
- package/dist/lib/opencode.types.d.ts.map +1 -0
- package/dist/lib/opencode.types.js +3 -0
- package/dist/lib/opencode.types.js.map +1 -0
- package/dist/lib/providers/anthropic.provider.d.ts +12 -0
- package/dist/lib/providers/anthropic.provider.d.ts.map +1 -0
- package/dist/lib/providers/anthropic.provider.js +187 -0
- package/dist/lib/providers/anthropic.provider.js.map +1 -0
- package/dist/lib/providers/llm-provider.interface.d.ts +71 -0
- package/dist/lib/providers/llm-provider.interface.d.ts.map +1 -0
- package/dist/lib/providers/llm-provider.interface.js +3 -0
- package/dist/lib/providers/llm-provider.interface.js.map +1 -0
- package/dist/lib/providers/openai.provider.d.ts +9 -0
- package/dist/lib/providers/openai.provider.d.ts.map +1 -0
- package/dist/lib/providers/openai.provider.js +103 -0
- package/dist/lib/providers/openai.provider.js.map +1 -0
- package/dist/lib/worker-proxy-helpers.d.ts +3 -0
- package/dist/lib/worker-proxy-helpers.d.ts.map +1 -0
- package/dist/lib/worker-proxy-helpers.js +37 -0
- package/dist/lib/worker-proxy-helpers.js.map +1 -0
- package/package.json +43 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface AgentConfig {
|
|
2
|
+
systemPrompt: string;
|
|
3
|
+
samplingProfile?: import('@xemahq/kernel-contracts/workflow').SamplingProfile;
|
|
4
|
+
directLlm?: boolean;
|
|
5
|
+
openCodeAgent?: string;
|
|
6
|
+
contextFiles?: Array<{
|
|
7
|
+
path: string;
|
|
8
|
+
reason: string;
|
|
9
|
+
}>;
|
|
10
|
+
mcpProfileKey?: string;
|
|
11
|
+
mcpServices?: string[];
|
|
12
|
+
}
|
|
13
|
+
export declare enum AgentCategory {
|
|
14
|
+
Pipeline = "pipeline",
|
|
15
|
+
GateReviewer = "gate-reviewer",
|
|
16
|
+
Utility = "utility",
|
|
17
|
+
PrePipeline = "pre-pipeline"
|
|
18
|
+
}
|
|
19
|
+
export interface AgentRegistration {
|
|
20
|
+
readonly key: string;
|
|
21
|
+
readonly category: AgentCategory;
|
|
22
|
+
readonly config: AgentConfig;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/lib/agents/types.ts"],"names":[],"mappings":"AAgBA,MAAM,WAAW,WAAW;IAE1B,YAAY,EAAE,MAAM,CAAC;IAUrB,eAAe,CAAC,EAAE,OAAO,mCAAmC,EAAE,eAAe,CAAC;IAM9E,SAAS,CAAC,EAAE,OAAO,CAAC;IAKpB,aAAa,CAAC,EAAE,MAAM,CAAC;IAOvB,YAAY,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAMvD,aAAa,CAAC,EAAE,MAAM,CAAC;IAKvB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;CACxB;AAeD,oBAAY,aAAa;IACvB,QAAQ,aAAa;IACrB,YAAY,kBAAkB;IAC9B,OAAO,YAAY;IACnB,WAAW,iBAAiB;CAC7B;AAOD,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC;IACjC,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;CAC9B"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AgentCategory = void 0;
|
|
4
|
+
var AgentCategory;
|
|
5
|
+
(function (AgentCategory) {
|
|
6
|
+
AgentCategory["Pipeline"] = "pipeline";
|
|
7
|
+
AgentCategory["GateReviewer"] = "gate-reviewer";
|
|
8
|
+
AgentCategory["Utility"] = "utility";
|
|
9
|
+
AgentCategory["PrePipeline"] = "pre-pipeline";
|
|
10
|
+
})(AgentCategory || (exports.AgentCategory = AgentCategory = {}));
|
|
11
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/lib/agents/types.ts"],"names":[],"mappings":";;;AAyEA,IAAY,aAKX;AALD,WAAY,aAAa;IACvB,sCAAqB,CAAA;IACrB,+CAA8B,CAAA;IAC9B,oCAAmB,CAAA;IACnB,6CAA4B,CAAA;AAC9B,CAAC,EALW,aAAa,6BAAb,aAAa,QAKxB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
type AgentCategory = 'builder' | 'coordinator' | 'reviewer' | 'utility' | 'pre-pipeline' | 'deployment';
|
|
2
|
+
export type InstructionMutabilityTier = 'system_locked' | 'system_default';
|
|
3
|
+
export interface InstructionSectionSeed {
|
|
4
|
+
sectionKey: string;
|
|
5
|
+
content: string;
|
|
6
|
+
categories: AgentCategory[];
|
|
7
|
+
mutabilityTier: InstructionMutabilityTier;
|
|
8
|
+
}
|
|
9
|
+
export declare const INSTRUCTION_SECTION_SEEDS: InstructionSectionSeed[];
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=agents-md-sections.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agents-md-sections.d.ts","sourceRoot":"","sources":["../../../src/lib/control-plane/agents-md-sections.ts"],"names":[],"mappings":"AA8BA,KAAK,aAAa,GACd,SAAS,GACT,aAAa,GACb,UAAU,GACV,SAAS,GACT,cAAc,GACd,YAAY,CAAC;AAkYjB,MAAM,MAAM,yBAAyB,GAAG,eAAe,GAAG,gBAAgB,CAAC;AAG3E,MAAM,WAAW,sBAAsB;IACrC,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,aAAa,EAAE,CAAC;IAC5B,cAAc,EAAE,yBAAyB,CAAC;CAC3C;AAcD,eAAO,MAAM,yBAAyB,EAAE,sBAAsB,EA6C1D,CAAC"}
|
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.INSTRUCTION_SECTION_SEEDS = void 0;
|
|
4
|
+
function buildWorkspaceMaterialModelSection() {
|
|
5
|
+
return '';
|
|
6
|
+
}
|
|
7
|
+
const EXECUTION_DISCIPLINE = `
|
|
8
|
+
## Execution Discipline
|
|
9
|
+
|
|
10
|
+
- **Read AGENTS.md first**: Before anything else, call \`read\` on \`/workspace/AGENTS.md\`. This is mandatory for every agent on every turn.
|
|
11
|
+
- **Plan first**: Before your first tool call, identify deliverables, required context, and execution sequence. Then act decisively.
|
|
12
|
+
- **Mandatory task tracking**: Use \`todowrite\` for every multi-step task, keep one item \`in_progress\`, and only finish when all todos are \`completed\`.
|
|
13
|
+
- **Persist until done**: If you hit an obstacle, try alternatives before reporting inability. Retry failed tool calls with corrected params.
|
|
14
|
+
- **No partial work**: Complete the phase fully or clearly report what remains and why.
|
|
15
|
+
`.trim();
|
|
16
|
+
const EVIDENCE_DISCIPLINE = `
|
|
17
|
+
## Evidence Discipline
|
|
18
|
+
|
|
19
|
+
Every action you take must produce traceable evidence:
|
|
20
|
+
- **File changes**: Note every file created, modified, or deleted.
|
|
21
|
+
- **Commands executed**: Record every shell command and its outcome (pass/fail).
|
|
22
|
+
- **Decisions made**: Document WHY you chose approach A over approach B.
|
|
23
|
+
- **Verification**: Run verification commands (build, test, lint) and report results.
|
|
24
|
+
- **Risk signals**: Flag any concerns — large change sets, missing tests, security implications.
|
|
25
|
+
|
|
26
|
+
The platform collects this evidence automatically from your tool calls.
|
|
27
|
+
Focus on producing clean, verifiable work — the evidence pack is built post-execution.
|
|
28
|
+
`.trim();
|
|
29
|
+
const REPORT_VS_DELIVERABLES = `
|
|
30
|
+
## Report vs Deliverables — Two Separate Deliverables
|
|
31
|
+
|
|
32
|
+
1. **DELIVERABLES** — actual work products created via MCP tools, file writes, or git. WHERE they go depends on your output channel rules.
|
|
33
|
+
2. **REPORT** — your text response. A structured account of what you did, NOT the deliverable content itself.
|
|
34
|
+
|
|
35
|
+
**Rules:**
|
|
36
|
+
- Report references deliverables by ID — it does NOT contain their content.
|
|
37
|
+
- Never dump full document/code content into the report as a "backup".
|
|
38
|
+
- If an MCP tool fails, retry with corrected params. If still failing, report the failure honestly — never fabricate deliverable references.
|
|
39
|
+
- Gate reviewers WILL cross-check your claims against actual artifacts.
|
|
40
|
+
`.trim();
|
|
41
|
+
const MEMORY_PRECEDENCE = `
|
|
42
|
+
## Memory Precedence Rule
|
|
43
|
+
|
|
44
|
+
When recalled memories conflict with current-run decisions:
|
|
45
|
+
- Current pipeline run's clarification decisions and requirements are AUTHORITATIVE.
|
|
46
|
+
- Prior-run project memories are ADVISORY only — use them as context, not constraints.
|
|
47
|
+
- Global (org-wide) memories are ADVISORY only unless they are explicit org-level constraints.
|
|
48
|
+
- If a global memory contradicts a current-run decision, the current-run decision wins.
|
|
49
|
+
`.trim();
|
|
50
|
+
const WORKSPACE_MATERIAL_MODEL = buildWorkspaceMaterialModelSection();
|
|
51
|
+
const CORRECTION_RECALL = `
|
|
52
|
+
## Corrections & Constraints — Highest Priority
|
|
53
|
+
|
|
54
|
+
Corrections from past runs are **pre-loaded into your context** (see "Prior Phase Context" / "Memories" sections above).
|
|
55
|
+
All memory is already injected — start from the provided context.
|
|
56
|
+
|
|
57
|
+
Handle corrections by confidence tier:
|
|
58
|
+
- **autoApply** (≥0.8): Follow without question — these override your default approach.
|
|
59
|
+
- **mention** (0.5–0.79): Include in reasoning, tell the user you're applying it.
|
|
60
|
+
- **suggest** (<0.5): Consider but don't auto-apply.
|
|
61
|
+
|
|
62
|
+
Corrections override gate feedback when they conflict. Never ignore autoApply corrections.
|
|
63
|
+
`.trim();
|
|
64
|
+
const GATE_FEEDBACK = `
|
|
65
|
+
## Learning From Past Gate Feedback
|
|
66
|
+
|
|
67
|
+
Gate feedback and platform best practices are **pre-loaded into your context** (see "Prior Phase Context" / "Memories" sections above).
|
|
68
|
+
All feedback is already injected — start from the provided context.
|
|
69
|
+
|
|
70
|
+
Apply the lessons:
|
|
71
|
+
- Gate rejection memories are HIGH-PRIORITY constraints — they represent real failures.
|
|
72
|
+
- Platform-scope memories are established best practices — deviate only with explicit justification.
|
|
73
|
+
- If past feedback conflicts with current task requirements, the current task takes priority (note the deviation).
|
|
74
|
+
|
|
75
|
+
If you discover actionable, reusable learnings during your work, include them in the manifest \`analyticalFindings\`. Memory creation happens automatically from gate feedback and outcomes.
|
|
76
|
+
`.trim();
|
|
77
|
+
const FILE_FIRST_OUTPUT = `
|
|
78
|
+
## File-First Output — Write Files, Harvest Server-Side
|
|
79
|
+
|
|
80
|
+
### The Rule: Your Deliverables Are JSON + Markdown Files on Disk
|
|
81
|
+
|
|
82
|
+
You produce your phase output by writing plain files to \`/workspace/\`.
|
|
83
|
+
The orchestrator harvests them after your turn completes, validates
|
|
84
|
+
them against the published output contracts, and sends an in-session
|
|
85
|
+
correction if anything is missing or malformed. No special emit tools —
|
|
86
|
+
just \`write\`.
|
|
87
|
+
|
|
88
|
+
### Page editing
|
|
89
|
+
|
|
90
|
+
Your pre-scaffolded pages live at \`deliverables/pages/<slug>.md\`. Edit in
|
|
91
|
+
place with \`md_edit\`, \`edit\`, \`patch\`, or \`write\`. Allowed slugs are
|
|
92
|
+
in \`context.json.authority.mayWriteSlugs\`; the biome rejects
|
|
93
|
+
unauthorized writes at \`tool.execute.before\` with a typed error.
|
|
94
|
+
|
|
95
|
+
### Required output files
|
|
96
|
+
|
|
97
|
+
| File | Contents |
|
|
98
|
+
|------|----------|
|
|
99
|
+
| \`deliverables/manifest.json\` | One entry per page: \`{ slug, title, contentFile }\`. System fields (schemaVersion, phaseKey, runId, timestamp, manifestHash) are injected at harvest — do not populate them. Written LAST, after all page files are on disk. |
|
|
100
|
+
| \`deliverables/analysis.json\` | Structured decisions, assumptions, conflicts, analytical findings. Optional — omit if you have nothing to record. |
|
|
101
|
+
| \`deliverables/page-expansion-proposal.json\` | When scope requires adding pages beyond the scaffold, propose them here (slug, title, rationale). Optional. |
|
|
102
|
+
|
|
103
|
+
### Completion signal
|
|
104
|
+
|
|
105
|
+
The orchestrator treats your turn as complete when the SSE stream
|
|
106
|
+
reaches \`session.idle\`. It then reads the files above. If any are
|
|
107
|
+
missing, malformed, or fail validation, you receive a correction
|
|
108
|
+
message listing each issue — fix and your next turn re-runs harvest.
|
|
109
|
+
|
|
110
|
+
Without a valid \`deliverables/manifest.json\`, your work is not saved.
|
|
111
|
+
|
|
112
|
+
### What Goes WHERE
|
|
113
|
+
|
|
114
|
+
| Content Type | Channel |
|
|
115
|
+
|---|---|
|
|
116
|
+
| Page bodies | \`deliverables/pages/<slug>.md\` (any mutation tool) |
|
|
117
|
+
| Phase manifest | \`deliverables/manifest.json\` (\`write\`) |
|
|
118
|
+
| Phase analysis | \`deliverables/analysis.json\` (\`write\`) |
|
|
119
|
+
| Page-expansion proposal | \`deliverables/page-expansion-proposal.json\` (\`write\`) |
|
|
120
|
+
| Backlog items | direct MCP (\`backlog_create_item\`) |
|
|
121
|
+
| Artifact registration | direct MCP (\`artifact_create\`) |
|
|
122
|
+
| Code / config files | \`write\` / \`edit\` / \`patch\` to repo paths |
|
|
123
|
+
`.trim();
|
|
124
|
+
const STANDARD_REPORT_FORMAT = `
|
|
125
|
+
## Standard Report Format (narrative agents only)
|
|
126
|
+
|
|
127
|
+
Structure your text response using these sections:
|
|
128
|
+
- **Summary** — one paragraph: goal, what was accomplished, status.
|
|
129
|
+
- **Actions Taken** — numbered list referencing tool calls and results.
|
|
130
|
+
- **Key Decisions** — decisions with brief rationale (or "None required").
|
|
131
|
+
- **Issues & Risks** — problems, unresolved concerns, or downstream risks (or "None").
|
|
132
|
+
- **Deliverables Produced** — itemized list: \`**[Type]**: [ID] — [description]\`
|
|
133
|
+
- **Self-Assessment** — Completeness X/10, Confidence X/10, Gaps.
|
|
134
|
+
|
|
135
|
+
NOTE: If your output contract specifies a strict JSON schema, follow that schema instead of this report format.
|
|
136
|
+
`.trim();
|
|
137
|
+
const INJECTED_CONTEXT = `
|
|
138
|
+
## Context Usage — Injected, Not Discovered
|
|
139
|
+
|
|
140
|
+
Your execution brief above contains all the context you need to start:
|
|
141
|
+
- **Corrections, gate feedback, preferences** — pre-loaded in prior sections.
|
|
142
|
+
- **Authoritative upstream refs** — provided in your task prompt. Use them directly.
|
|
143
|
+
- **Project orientation** — backlog summary, key decisions, and KB overview are injected above.
|
|
144
|
+
|
|
145
|
+
**Rules:**
|
|
146
|
+
- Context is preloaded. Start from injected context.
|
|
147
|
+
- Use \`search_documents\` if you have a specific evidence gap.
|
|
148
|
+
`.trim();
|
|
149
|
+
const COORDINATOR_OUTPUT_CONTRACT = `
|
|
150
|
+
## Output Contract — Coordinator Deliverables
|
|
151
|
+
|
|
152
|
+
Coordinator deliverables are plain files written to \`/workspace/deliverables/\`.
|
|
153
|
+
The orchestrator harvests + validates them after your turn completes.
|
|
154
|
+
|
|
155
|
+
1. **Cross-cutting pages** — edit files under \`deliverables/pages/<slug>.md\`
|
|
156
|
+
(allowed slugs are in \`context.json.authority.mayWriteSlugs\`; the
|
|
157
|
+
biome rejects worker-owned slugs with a typed error).
|
|
158
|
+
2. **Cross-unit consistency report** — write \`deliverables/consistency-report.json\`.
|
|
159
|
+
MANDATORY before you stop — the downstream reviewer reads it.
|
|
160
|
+
3. **Narrow patches** to worker-owned pages — apply via \`edit\` /
|
|
161
|
+
\`md_edit\` directly. No separate record file.
|
|
162
|
+
4. **Coordinator analysis** — write \`deliverables/analysis.json\` for
|
|
163
|
+
decisions and assumptions at the coordinator level.
|
|
164
|
+
5. **Phase manifest** — write \`deliverables/manifest.json\` LAST, after every
|
|
165
|
+
page and JSON file is on disk. Without a valid manifest, your work
|
|
166
|
+
is not saved.
|
|
167
|
+
|
|
168
|
+
Do not validate standards compliance or grade unit-worker content —
|
|
169
|
+
that is the reviewer's job. Your output is consolidation + consistency.
|
|
170
|
+
`.trim();
|
|
171
|
+
const REVIEWER_CONTEXT_USAGE = `
|
|
172
|
+
## Context Usage — Review Mode
|
|
173
|
+
|
|
174
|
+
Reviewer path contracts are single-sourced in runtime \`/workspace/AGENTS.md\`.
|
|
175
|
+
Do not infer or rewrite path conventions from memory.
|
|
176
|
+
|
|
177
|
+
Reviewer inputs include template contract, deliverable pages under review,
|
|
178
|
+
review-brief/coordinator-report when mounted, and upstream approved artifacts.
|
|
179
|
+
Read review-brief first when present.
|
|
180
|
+
|
|
181
|
+
**Rules:**
|
|
182
|
+
- Read mounted files with \`read\` / \`glob\` — they are canonical.
|
|
183
|
+
- Obey the template's \`scope\` and \`reviewDimensions\`. If a finding's remedy would require a different phase's agent to produce the fix, it is out of scope — drop it.
|
|
184
|
+
- Write your verdict to \`deliverables/review.json\` matching the \`reviewer-output\` deliverable spec (\`verdict\` = \`approve\` | \`reject\` | \`abstain\`; structured \`summary\`, \`findings\`, optional \`suggestedEdits\`). The harvester validates against the spec — schema errors fail the gate.
|
|
185
|
+
`.trim();
|
|
186
|
+
const DEPLOYMENT_SCM_SAFETY = `
|
|
187
|
+
## SCM Safety Rules
|
|
188
|
+
|
|
189
|
+
- NEVER merge to the target branch — dry-run validation only.
|
|
190
|
+
- NEVER push to any remote branch.
|
|
191
|
+
- NEVER force push (\`git push --force\` or \`--force-with-lease\`).
|
|
192
|
+
- NEVER amend commits.
|
|
193
|
+
- NEVER rewrite history on shared branches.
|
|
194
|
+
- NEVER resolve merge conflicts — abort and self-reject.
|
|
195
|
+
- If anything goes wrong, self-reject with a \`:::TASK_REJECTION:::\` block.
|
|
196
|
+
`.trim();
|
|
197
|
+
const GIT_WORKFLOW = `
|
|
198
|
+
## Git Workflow
|
|
199
|
+
|
|
200
|
+
### Commit Message Format (Conventional Commits)
|
|
201
|
+
|
|
202
|
+
\`\`\`
|
|
203
|
+
<type>(<scope>): <subject>
|
|
204
|
+
|
|
205
|
+
<body>
|
|
206
|
+
|
|
207
|
+
<footer>
|
|
208
|
+
\`\`\`
|
|
209
|
+
|
|
210
|
+
| Type | When |
|
|
211
|
+
|------|------|
|
|
212
|
+
| \`feat\` | New feature or capability |
|
|
213
|
+
| \`fix\` | Bug fix |
|
|
214
|
+
| \`refactor\` | Code restructuring without behavior change |
|
|
215
|
+
| \`docs\` | Documentation only |
|
|
216
|
+
| \`test\` | Adding or updating tests |
|
|
217
|
+
| \`chore\` | Build, config, tooling changes |
|
|
218
|
+
| \`perf\` | Performance improvement |
|
|
219
|
+
|
|
220
|
+
- Subject line: max 72 characters, imperative mood ("add" not "added")
|
|
221
|
+
- Scope: module, service, or area affected (e.g., \`auth\`, \`api\`, \`db\`)
|
|
222
|
+
- Body: explain WHAT and WHY, not HOW (the diff shows how)
|
|
223
|
+
|
|
224
|
+
### Staging Strategy
|
|
225
|
+
|
|
226
|
+
- **Atomic commits**: Each commit should represent ONE logical change.
|
|
227
|
+
- **Check before staging**: \`git status\` and \`git diff\` to review all changes.
|
|
228
|
+
- **Stage related files together**: Don't mix unrelated changes in one commit.
|
|
229
|
+
- **Never commit generated files**: Build output, lock files (unless intentional), \`.env\` files.
|
|
230
|
+
|
|
231
|
+
### Rules
|
|
232
|
+
|
|
233
|
+
- NEVER force-push — this destroys history.
|
|
234
|
+
- NEVER amend commits that have been pushed.
|
|
235
|
+
- NEVER commit secrets, credentials, or large binary files.
|
|
236
|
+
- ALWAYS pull before push to avoid conflicts.
|
|
237
|
+
`.trim();
|
|
238
|
+
const GOVERNANCE_CONSTRAINTS = `
|
|
239
|
+
## Pipeline Governance
|
|
240
|
+
|
|
241
|
+
- You are operating within a governed pipeline run.
|
|
242
|
+
- You may only submit candidate artifacts, patches, evidence, and review notes.
|
|
243
|
+
- You may NOT directly mutate canonical workflow state, trigger phase transitions, or approve/merge artifacts.
|
|
244
|
+
- All writes are proposals — the platform decides what becomes canonical after validation and approval.
|
|
245
|
+
`.trim();
|
|
246
|
+
const WORKSPACE_CONTEXT = `
|
|
247
|
+
## Workspace & Platform Context
|
|
248
|
+
|
|
249
|
+
Your workspace root is \`/workspace/\`.
|
|
250
|
+
|
|
251
|
+
- Project code lives in \`/workspace/repos/<slug>/\`.
|
|
252
|
+
- \`references/\` contains curated read-only evidence for this run.
|
|
253
|
+
- \`inputs/\` contains invocation-scoped raw material (prompt payloads, schemas, retry instructions).
|
|
254
|
+
- \`deliverables/\` is the writable area for pipeline deliverables.
|
|
255
|
+
- \`attachments/\` contains user uploads (read-only).
|
|
256
|
+
- \`.xema/\` and \`.opencode/\` are platform internals; do not modify them unless the task explicitly requires it.
|
|
257
|
+
|
|
258
|
+
Use \`context.json\` authority to decide what is writable, and prefer targeted reads over broad repository scans.
|
|
259
|
+
`.trim();
|
|
260
|
+
const CATEGORY_SECTIONS = {
|
|
261
|
+
builder: [
|
|
262
|
+
EXECUTION_DISCIPLINE,
|
|
263
|
+
EVIDENCE_DISCIPLINE,
|
|
264
|
+
REPORT_VS_DELIVERABLES,
|
|
265
|
+
STANDARD_REPORT_FORMAT,
|
|
266
|
+
MEMORY_PRECEDENCE,
|
|
267
|
+
WORKSPACE_MATERIAL_MODEL,
|
|
268
|
+
CORRECTION_RECALL,
|
|
269
|
+
GATE_FEEDBACK,
|
|
270
|
+
FILE_FIRST_OUTPUT,
|
|
271
|
+
INJECTED_CONTEXT,
|
|
272
|
+
WORKSPACE_CONTEXT,
|
|
273
|
+
GIT_WORKFLOW,
|
|
274
|
+
GOVERNANCE_CONSTRAINTS,
|
|
275
|
+
],
|
|
276
|
+
coordinator: [
|
|
277
|
+
EXECUTION_DISCIPLINE,
|
|
278
|
+
EVIDENCE_DISCIPLINE,
|
|
279
|
+
REPORT_VS_DELIVERABLES,
|
|
280
|
+
MEMORY_PRECEDENCE,
|
|
281
|
+
WORKSPACE_MATERIAL_MODEL,
|
|
282
|
+
CORRECTION_RECALL,
|
|
283
|
+
GATE_FEEDBACK,
|
|
284
|
+
FILE_FIRST_OUTPUT,
|
|
285
|
+
INJECTED_CONTEXT,
|
|
286
|
+
WORKSPACE_CONTEXT,
|
|
287
|
+
COORDINATOR_OUTPUT_CONTRACT,
|
|
288
|
+
GOVERNANCE_CONSTRAINTS,
|
|
289
|
+
],
|
|
290
|
+
reviewer: [
|
|
291
|
+
EXECUTION_DISCIPLINE,
|
|
292
|
+
EVIDENCE_DISCIPLINE,
|
|
293
|
+
REPORT_VS_DELIVERABLES,
|
|
294
|
+
MEMORY_PRECEDENCE,
|
|
295
|
+
WORKSPACE_MATERIAL_MODEL,
|
|
296
|
+
REVIEWER_CONTEXT_USAGE,
|
|
297
|
+
WORKSPACE_CONTEXT,
|
|
298
|
+
GOVERNANCE_CONSTRAINTS,
|
|
299
|
+
],
|
|
300
|
+
utility: [
|
|
301
|
+
EXECUTION_DISCIPLINE,
|
|
302
|
+
EVIDENCE_DISCIPLINE,
|
|
303
|
+
MEMORY_PRECEDENCE,
|
|
304
|
+
WORKSPACE_MATERIAL_MODEL,
|
|
305
|
+
WORKSPACE_CONTEXT,
|
|
306
|
+
GOVERNANCE_CONSTRAINTS,
|
|
307
|
+
],
|
|
308
|
+
'pre-pipeline': [EXECUTION_DISCIPLINE, WORKSPACE_MATERIAL_MODEL, WORKSPACE_CONTEXT],
|
|
309
|
+
deployment: [
|
|
310
|
+
EXECUTION_DISCIPLINE,
|
|
311
|
+
EVIDENCE_DISCIPLINE,
|
|
312
|
+
REPORT_VS_DELIVERABLES,
|
|
313
|
+
STANDARD_REPORT_FORMAT,
|
|
314
|
+
WORKSPACE_MATERIAL_MODEL,
|
|
315
|
+
INJECTED_CONTEXT,
|
|
316
|
+
WORKSPACE_CONTEXT,
|
|
317
|
+
GIT_WORKFLOW,
|
|
318
|
+
DEPLOYMENT_SCM_SAFETY,
|
|
319
|
+
GOVERNANCE_CONSTRAINTS,
|
|
320
|
+
],
|
|
321
|
+
};
|
|
322
|
+
const SYSTEM_LOCKED_KEYS = new Set([
|
|
323
|
+
'GOVERNANCE_CONSTRAINTS',
|
|
324
|
+
'DEPLOYMENT_SCM_SAFETY',
|
|
325
|
+
]);
|
|
326
|
+
exports.INSTRUCTION_SECTION_SEEDS = (() => {
|
|
327
|
+
const sectionMap = [
|
|
328
|
+
{ key: 'EXECUTION_DISCIPLINE', content: EXECUTION_DISCIPLINE },
|
|
329
|
+
{ key: 'EVIDENCE_DISCIPLINE', content: EVIDENCE_DISCIPLINE },
|
|
330
|
+
{ key: 'REPORT_VS_DELIVERABLES', content: REPORT_VS_DELIVERABLES },
|
|
331
|
+
{ key: 'STANDARD_REPORT_FORMAT', content: STANDARD_REPORT_FORMAT },
|
|
332
|
+
{ key: 'MEMORY_PRECEDENCE', content: MEMORY_PRECEDENCE },
|
|
333
|
+
{ key: 'WORKSPACE_MATERIAL_MODEL', content: WORKSPACE_MATERIAL_MODEL },
|
|
334
|
+
{ key: 'CORRECTION_RECALL', content: CORRECTION_RECALL },
|
|
335
|
+
{ key: 'GATE_FEEDBACK', content: GATE_FEEDBACK },
|
|
336
|
+
{ key: 'FILE_FIRST_OUTPUT', content: FILE_FIRST_OUTPUT },
|
|
337
|
+
{ key: 'INJECTED_CONTEXT', content: INJECTED_CONTEXT },
|
|
338
|
+
{ key: 'COORDINATOR_OUTPUT_CONTRACT', content: COORDINATOR_OUTPUT_CONTRACT },
|
|
339
|
+
{ key: 'REVIEWER_CONTEXT_USAGE', content: REVIEWER_CONTEXT_USAGE },
|
|
340
|
+
{ key: 'DEPLOYMENT_SCM_SAFETY', content: DEPLOYMENT_SCM_SAFETY },
|
|
341
|
+
{ key: 'GIT_WORKFLOW', content: GIT_WORKFLOW },
|
|
342
|
+
{ key: 'WORKSPACE_CONTEXT', content: WORKSPACE_CONTEXT },
|
|
343
|
+
{ key: 'GOVERNANCE_CONSTRAINTS', content: GOVERNANCE_CONSTRAINTS },
|
|
344
|
+
];
|
|
345
|
+
const contentToKey = new Map(sectionMap.map((s) => [s.content, s.key]));
|
|
346
|
+
const sectionCategories = new Map();
|
|
347
|
+
for (const [category, sections] of Object.entries(CATEGORY_SECTIONS)) {
|
|
348
|
+
for (const sectionContent of sections) {
|
|
349
|
+
const key = contentToKey.get(sectionContent);
|
|
350
|
+
if (!key)
|
|
351
|
+
continue;
|
|
352
|
+
if (!sectionCategories.has(key)) {
|
|
353
|
+
sectionCategories.set(key, new Set());
|
|
354
|
+
}
|
|
355
|
+
sectionCategories.get(key).add(category);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
return sectionMap.map((s) => ({
|
|
359
|
+
sectionKey: s.key,
|
|
360
|
+
content: s.content,
|
|
361
|
+
categories: [...(sectionCategories.get(s.key) ?? [])],
|
|
362
|
+
mutabilityTier: SYSTEM_LOCKED_KEYS.has(s.key)
|
|
363
|
+
? 'system_locked'
|
|
364
|
+
: 'system_default',
|
|
365
|
+
}));
|
|
366
|
+
})();
|
|
367
|
+
//# sourceMappingURL=agents-md-sections.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agents-md-sections.js","sourceRoot":"","sources":["../../../src/lib/control-plane/agents-md-sections.ts"],"names":[],"mappings":";;;AAsBA,SAAS,kCAAkC;IACzC,OAAO,EAAE,CAAC;AACZ,CAAC;AAyBD,MAAM,oBAAoB,GAAG;;;;;;;;CAQ5B,CAAC,IAAI,EAAE,CAAC;AAET,MAAM,mBAAmB,GAAG;;;;;;;;;;;;CAY3B,CAAC,IAAI,EAAE,CAAC;AAET,MAAM,sBAAsB,GAAG;;;;;;;;;;;CAW9B,CAAC,IAAI,EAAE,CAAC;AAET,MAAM,iBAAiB,GAAG;;;;;;;;CAQzB,CAAC,IAAI,EAAE,CAAC;AAET,MAAM,wBAAwB,GAAG,kCAAkC,EAAE,CAAC;AAMtE,MAAM,iBAAiB,GAAG;;;;;;;;;;;;CAYzB,CAAC,IAAI,EAAE,CAAC;AAET,MAAM,aAAa,GAAG;;;;;;;;;;;;CAYrB,CAAC,IAAI,EAAE,CAAC;AAET,MAAM,iBAAiB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8CzB,CAAC,IAAI,EAAE,CAAC;AAET,MAAM,sBAAsB,GAAG;;;;;;;;;;;;CAY9B,CAAC,IAAI,EAAE,CAAC;AAET,MAAM,gBAAgB,GAAG;;;;;;;;;;;CAWxB,CAAC,IAAI,EAAE,CAAC;AAMT,MAAM,2BAA2B,GAAG;;;;;;;;;;;;;;;;;;;;;CAqBnC,CAAC,IAAI,EAAE,CAAC;AAMT,MAAM,sBAAsB,GAAG;;;;;;;;;;;;;;CAc9B,CAAC,IAAI,E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src/lib/control-plane/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AACjE,YAAY,EACV,sBAAsB,EACtB,yBAAyB,GAC1B,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.INSTRUCTION_SECTION_SEEDS = void 0;
|
|
4
|
+
var agents_md_sections_1 = require("./agents-md-sections");
|
|
5
|
+
Object.defineProperty(exports, "INSTRUCTION_SECTION_SEEDS", { enumerable: true, get: function () { return agents_md_sections_1.INSTRUCTION_SECTION_SEEDS; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/control-plane/index.ts"],"names":[],"mappings":";;;AASA,2DAAiE;AAAxD,+HAAA,yBAAyB,OAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Logger } from '@nestjs/common';
|
|
2
|
+
import type { OpenCodeConfig } from './opencode-config.interface';
|
|
3
|
+
import type { DirectLlmProvider } from './modes/direct-llm.provider';
|
|
4
|
+
import type { DirectLlmInput, DirectLlmResult } from './opencode.types';
|
|
5
|
+
export interface DirectLlmDeps {
|
|
6
|
+
logger: Logger;
|
|
7
|
+
config: OpenCodeConfig;
|
|
8
|
+
directLlm: DirectLlmProvider;
|
|
9
|
+
}
|
|
10
|
+
export declare function executeDirectLlmToolLoop(input: DirectLlmInput, deps: DirectLlmDeps): Promise<DirectLlmResult>;
|
|
11
|
+
//# sourceMappingURL=direct-llm-invoker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"direct-llm-invoker.d.ts","sourceRoot":"","sources":["../../src/lib/direct-llm-invoker.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAOrE,OAAO,KAAK,EAEV,cAAc,EACd,eAAe,EAChB,MAAM,kBAAkB,CAAC;AAO1B,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,cAAc,CAAC;IACvB,SAAS,EAAE,iBAAiB,CAAC;CAC9B;AAgHD,wBAAsB,wBAAwB,CAC5C,KAAK,EAAE,cAAc,EACrB,IAAI,EAAE,aAAa,GAClB,OAAO,CAAC,eAAe,CAAC,CAsN1B"}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.executeDirectLlmToolLoop = executeDirectLlmToolLoop;
|
|
4
|
+
const llm_registry_client_1 = require("./llm-registry-client");
|
|
5
|
+
const opencode_utils_1 = require("./opencode-utils");
|
|
6
|
+
const openai_provider_1 = require("./providers/openai.provider");
|
|
7
|
+
const anthropic_provider_1 = require("./providers/anthropic.provider");
|
|
8
|
+
async function resolveGatewayOrDirectProvider(deps, registryConfig, orgId, projectId, phaseKey, runId) {
|
|
9
|
+
const { logger, config, directLlm } = deps;
|
|
10
|
+
if (config.llmRegistryApiUrl && config.serviceTokenProvider) {
|
|
11
|
+
const serviceToken = await config.serviceTokenProvider();
|
|
12
|
+
const providerTier = registryConfig.providerIsSystem
|
|
13
|
+
? 'MANAGED'
|
|
14
|
+
: 'BYOK';
|
|
15
|
+
const providerId = registryConfig.opencodeProviderId ||
|
|
16
|
+
registryConfig.providerId ||
|
|
17
|
+
registryConfig.providerName ||
|
|
18
|
+
'unknown';
|
|
19
|
+
const gatewayTokenRes = await fetch(`${config.llmRegistryApiUrl.replace(/\/+$/, '')}/internal/gateway-tokens`, {
|
|
20
|
+
method: 'POST',
|
|
21
|
+
headers: {
|
|
22
|
+
'Content-Type': 'application/json',
|
|
23
|
+
Authorization: `Bearer ${serviceToken}`,
|
|
24
|
+
'X-Org-Id': orgId,
|
|
25
|
+
...(projectId && { 'X-Project-Id': projectId }),
|
|
26
|
+
},
|
|
27
|
+
body: JSON.stringify({
|
|
28
|
+
userId: 'system',
|
|
29
|
+
providerId,
|
|
30
|
+
modelId: registryConfig.modelId,
|
|
31
|
+
providerTier,
|
|
32
|
+
groupCategory: runId ? 'PIPELINE' : phaseKey ? 'AGENT' : 'DIRECT',
|
|
33
|
+
metadata: {
|
|
34
|
+
...(runId && { pipelineRunId: runId }),
|
|
35
|
+
...(phaseKey && { phaseKey, agentKey: phaseKey }),
|
|
36
|
+
},
|
|
37
|
+
}),
|
|
38
|
+
signal: AbortSignal.timeout(10_000),
|
|
39
|
+
});
|
|
40
|
+
if (!gatewayTokenRes.ok) {
|
|
41
|
+
const errBody = await gatewayTokenRes
|
|
42
|
+
.text()
|
|
43
|
+
.catch(() => 'Unknown error');
|
|
44
|
+
throw new Error(`Failed to create gateway session for phase="${phaseKey}": ${gatewayTokenRes.status} ${errBody}`);
|
|
45
|
+
}
|
|
46
|
+
const { data: gatewaySession } = (await gatewayTokenRes.json());
|
|
47
|
+
logger.log(`Direct LLM: routing through gateway native proxy for phase="${phaseKey}" (provider=${providerId}, tier=${providerTier})`);
|
|
48
|
+
const isAnthropic = (registryConfig.providerName ?? '').toLowerCase() === 'anthropic';
|
|
49
|
+
if (isAnthropic) {
|
|
50
|
+
return new anthropic_provider_1.AnthropicProvider(gatewaySession.token, `${gatewaySession.nativeProxyUrl}/anthropic`, `gateway:anthropic`);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
return new openai_provider_1.OpenAiProvider(gatewaySession.token, `${gatewaySession.nativeProxyUrl}/openai/v1`, `gateway:${registryConfig.providerName ?? 'openai'}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return directLlm.getOrCreateRegistryProvider(registryConfig);
|
|
57
|
+
}
|
|
58
|
+
async function executeDirectLlmToolLoop(input, deps) {
|
|
59
|
+
const { logger } = deps;
|
|
60
|
+
const { systemPrompt, userPrompt, temperature, orgId, projectId, phaseKey, contextMessages, tools, toolChoice, toolExecutor, maxToolRounds = 10, signal, } = input;
|
|
61
|
+
if (signal?.aborted) {
|
|
62
|
+
throw new Error('runDirectLlm aborted before start');
|
|
63
|
+
}
|
|
64
|
+
if (tools?.length && !toolExecutor) {
|
|
65
|
+
throw new Error('runDirectLlm: `toolExecutor` callback is required when `tools` are provided');
|
|
66
|
+
}
|
|
67
|
+
if (!input.modelOverride && !phaseKey) {
|
|
68
|
+
throw new Error('runDirectLlm: `phaseKey` is required for LLM Registry model resolution. ' +
|
|
69
|
+
'Pass the pipeline phase key (e.g., "requirements", "engineering") to resolve the correct model, ' +
|
|
70
|
+
'or provide `modelOverride` to bypass registry resolution.');
|
|
71
|
+
}
|
|
72
|
+
const registryConfig = input.modelOverride ?? await (0, llm_registry_client_1.resolveFromRegistry)(logger, orgId, projectId, phaseKey);
|
|
73
|
+
const providerInstance = await resolveGatewayOrDirectProvider(deps, registryConfig, orgId, projectId, phaseKey, input.runId);
|
|
74
|
+
const hasTools = tools && tools.length > 0;
|
|
75
|
+
logger.log(`runDirectLlm: model="${registryConfig.modelId}" provider="${registryConfig.providerName}"` +
|
|
76
|
+
(hasTools
|
|
77
|
+
? ` tools=[${tools.map((t) => t.function.name).join(',')}]`
|
|
78
|
+
: ''));
|
|
79
|
+
const messages = [{ role: 'system', content: systemPrompt }];
|
|
80
|
+
if (contextMessages?.length) {
|
|
81
|
+
for (const ctx of contextMessages) {
|
|
82
|
+
messages.push({ role: ctx.role, content: ctx.content });
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
messages.push({ role: 'user', content: userPrompt });
|
|
86
|
+
const cumulativeUsage = {
|
|
87
|
+
promptTokens: 0,
|
|
88
|
+
completionTokens: 0,
|
|
89
|
+
totalTokens: 0,
|
|
90
|
+
};
|
|
91
|
+
let toolRounds = 0;
|
|
92
|
+
const toolFailureCounts = new Map();
|
|
93
|
+
const MAX_IDENTICAL_FAILURES = 1;
|
|
94
|
+
while (true) {
|
|
95
|
+
if (signal?.aborted) {
|
|
96
|
+
throw new Error('runDirectLlm aborted during tool-calling loop');
|
|
97
|
+
}
|
|
98
|
+
const response = await providerInstance.complete({
|
|
99
|
+
model: registryConfig.modelId,
|
|
100
|
+
messages,
|
|
101
|
+
temperature: temperature ?? 0.2,
|
|
102
|
+
...(hasTools ? { tools: tools } : {}),
|
|
103
|
+
...(hasTools && toolChoice !== undefined
|
|
104
|
+
? { tool_choice: toolChoice }
|
|
105
|
+
: {}),
|
|
106
|
+
});
|
|
107
|
+
cumulativeUsage.promptTokens += response.usage.promptTokens;
|
|
108
|
+
cumulativeUsage.completionTokens += response.usage.completionTokens;
|
|
109
|
+
cumulativeUsage.totalTokens += response.usage.totalTokens;
|
|
110
|
+
if (!response.toolCalls?.length || !toolExecutor) {
|
|
111
|
+
logger.log(`runDirectLlm: completed in ${toolRounds} tool rounds, ` +
|
|
112
|
+
`${cumulativeUsage.totalTokens} total tokens, model="${response.model}"`);
|
|
113
|
+
return {
|
|
114
|
+
content: (0, opencode_utils_1.stripThinkingTags)(response.content),
|
|
115
|
+
model: response.model,
|
|
116
|
+
usage: cumulativeUsage,
|
|
117
|
+
toolRounds,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
toolRounds++;
|
|
121
|
+
if (toolRounds > maxToolRounds) {
|
|
122
|
+
logger.warn(`runDirectLlm: hit maxToolRounds=${maxToolRounds}, returning last response`);
|
|
123
|
+
return {
|
|
124
|
+
content: (0, opencode_utils_1.stripThinkingTags)(response.content),
|
|
125
|
+
model: response.model,
|
|
126
|
+
usage: cumulativeUsage,
|
|
127
|
+
toolRounds,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
logger.log(`runDirectLlm: round ${toolRounds} — model called ${response.toolCalls.length} tool(s): ` +
|
|
131
|
+
`[${response.toolCalls.map((tc) => tc.function.name).join(', ')}]`);
|
|
132
|
+
messages.push({
|
|
133
|
+
role: 'assistant',
|
|
134
|
+
content: response.content || null,
|
|
135
|
+
tool_calls: response.toolCalls,
|
|
136
|
+
});
|
|
137
|
+
const toolResults = await toolExecutor(response.toolCalls.map((tc) => ({
|
|
138
|
+
id: tc.id,
|
|
139
|
+
name: tc.function.name,
|
|
140
|
+
arguments: tc.function.arguments,
|
|
141
|
+
})));
|
|
142
|
+
let repeatedFailureDetected = false;
|
|
143
|
+
for (const result of toolResults) {
|
|
144
|
+
const matchingCall = response.toolCalls.find((tc) => tc.id === result.toolCallId);
|
|
145
|
+
if (result.isError && matchingCall) {
|
|
146
|
+
const failureKey = `${matchingCall.function.name}:${matchingCall.function.arguments}`;
|
|
147
|
+
const count = (toolFailureCounts.get(failureKey) ?? 0) + 1;
|
|
148
|
+
toolFailureCounts.set(failureKey, count);
|
|
149
|
+
if (count > MAX_IDENTICAL_FAILURES) {
|
|
150
|
+
repeatedFailureDetected = true;
|
|
151
|
+
logger.warn(`runDirectLlm: tool "${matchingCall.function.name}" failed ${count} times with identical args — injecting deterministic stop`);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
else if (matchingCall) {
|
|
155
|
+
const successKey = `${matchingCall.function.name}:${matchingCall.function.arguments}`;
|
|
156
|
+
toolFailureCounts.delete(successKey);
|
|
157
|
+
}
|
|
158
|
+
messages.push({
|
|
159
|
+
role: 'tool',
|
|
160
|
+
tool_call_id: result.toolCallId,
|
|
161
|
+
content: result.isError
|
|
162
|
+
? `[ERROR] ${result.content}`
|
|
163
|
+
: result.content,
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
if (repeatedFailureDetected) {
|
|
167
|
+
messages.push({
|
|
168
|
+
role: 'user',
|
|
169
|
+
content: '[SYSTEM] One or more tool calls failed repeatedly with identical arguments. ' +
|
|
170
|
+
'Do NOT retry the same call. Either use different arguments, use a different tool, ' +
|
|
171
|
+
'or proceed without the failing tool result.',
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
//# sourceMappingURL=direct-llm-invoker.js.map
|