@sanqianx/claude-ai-workbench 0.13.2 → 0.13.4
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 -201
- package/README.md +156 -156
- package/apps/agent-terminal/app.css +652 -613
- package/apps/agent-terminal/app.js +143 -67
- package/apps/agent-terminal/conversation-composer.js +44 -0
- package/apps/agent-terminal/index.html +172 -170
- package/apps/agent-terminal/panel-host-proof.html +152 -152
- package/apps/agent-terminal/panel-proof-content.html +41 -41
- package/apps/agent-terminal/right-workspace-dock.css +189 -159
- package/apps/agent-terminal/right-workspace-dock.js +652 -521
- package/apps/agent-terminal/user-question-card.js +68 -0
- package/apps/ai-profile-settings-host/index.html +25 -25
- package/apps/ai-profile-settings-host/page.css +1 -1
- package/apps/ai-profile-settings-host/page.js +113 -113
- package/apps/minimal-test-host/README.md +15 -15
- package/apps/minimal-test-host/host.css +2 -2
- package/apps/minimal-test-host/host.js +35 -35
- package/apps/minimal-test-host/index.html +58 -58
- package/apps/minimal-test-host/optional-mock/fault-injection.js +15 -15
- package/docs/sdk/FILE_LAYOUT.md +31 -31
- package/docs/sdk/INTEGRATION.md +126 -126
- package/docs/sdk/README.md +21 -21
- package/docs/sdk/SESSION_EVENTS.md +15 -13
- package/docs/sdk/openapi.yaml +16 -1
- package/package.json +1 -1
- package/packages/client/README.md +29 -29
- package/packages/client/index.d.ts +122 -122
- package/packages/client/index.js +260 -260
- package/packages/client/package.json +2 -2
- package/packages/contracts/README.md +9 -9
- package/packages/contracts/index.d.ts +519 -517
- package/packages/contracts/index.js +312 -312
- package/packages/contracts/package.json +1 -1
- package/packages/core/README.md +8 -8
- package/packages/core/index.d.ts +76 -76
- package/packages/core/index.js +222 -222
- package/packages/core/package.json +2 -2
- package/packages/server/README.md +17 -17
- package/packages/server/bin/agent-terminal-server.js +42 -42
- package/packages/server/bin/claude-workbench.js +225 -225
- package/packages/server/index.d.ts +171 -171
- package/packages/server/index.js +230 -230
- package/packages/server/lib/agent-discovery.js +133 -133
- package/packages/server/lib/agent-registry.js +143 -143
- package/packages/server/lib/agent-spawn-env.js +17 -17
- package/packages/server/lib/attachment-store.js +78 -78
- package/packages/server/lib/bridges/app-server-bridge.js +373 -373
- package/packages/server/lib/bridges/opencode-server-bridge.js +506 -506
- package/packages/server/lib/capture-settings-store.js +35 -35
- package/packages/server/lib/claude-history-recovery.js +87 -87
- package/packages/server/lib/cli-session-recovery.js +28 -28
- package/packages/server/lib/context-resolver.js +55 -55
- package/packages/server/lib/conversation-capture.js +51 -51
- package/packages/server/lib/delegation-phase-store.js +357 -357
- package/packages/server/lib/delegation-store.js +474 -468
- package/packages/server/lib/diagnostics.js +32 -32
- package/packages/server/lib/drivers/cli-json-runner.js +974 -974
- package/packages/server/lib/drivers/codex-driver.js +1461 -1442
- package/packages/server/lib/drivers/opencode-driver.js +1554 -1554
- package/packages/server/lib/drivers/zcode-driver.js +1250 -1250
- package/packages/server/lib/drivers/zcode-profile-runtime.js +71 -71
- package/packages/server/lib/event-stream.js +138 -138
- package/packages/server/lib/folder-picker.js +623 -623
- package/packages/server/lib/http-handler.js +339 -339
- package/packages/server/lib/json-file.js +26 -26
- package/packages/server/lib/knowledge-context.js +33 -33
- package/packages/server/lib/model-detection.js +295 -295
- package/packages/server/lib/parent-context.js +44 -0
- package/packages/server/lib/profile-store.js +283 -283
- package/packages/server/lib/project-store.js +102 -102
- package/packages/server/lib/runtime-loader.js +120 -120
- package/packages/server/lib/session-archive-store.js +53 -53
- package/packages/server/lib/session-history.js +612 -612
- package/packages/server/lib/system-doctor.js +125 -125
- package/packages/server/lib/ui-preferences-store.js +48 -48
- package/packages/server/lib/user-questions.js +67 -0
- package/packages/server/lib/workbench-service.js +1696 -1675
- package/packages/server/package.json +2 -2
- package/packages/ui/README.md +30 -30
- package/packages/ui/ai-profile-settings.d.ts +45 -45
- package/packages/ui/ai-profile-settings.js +283 -283
- package/packages/ui/claude-terminal.d.ts +31 -31
- package/packages/ui/claude-terminal.js +343 -343
- package/packages/ui/index.d.ts +18 -18
- package/packages/ui/index.js +51 -51
- package/packages/ui/package.json +2 -2
- package/packages/ui/theme.css +13 -13
- package/src/assets/claude-prompts.json +21 -21
- package/src/backend/http/ai-profile-routes.js +61 -61
- package/src/backend/http/claude-routes.js +170 -170
- package/src/backend/http/node-helpers.js +45 -45
- package/src/backend/index.js +21 -21
- package/src/backend/lib/ai-adapter.js +144 -144
- package/src/backend/lib/ai-profile-store.js +259 -259
- package/src/backend/lib/ai-vendor-presets.js +83 -83
- package/src/backend/lib/ai-workspace.js +140 -140
- package/src/backend/lib/automation-config.js +253 -253
- package/src/backend/lib/claude-cli-runner.js +2408 -2392
- package/src/backend/lib/data-dir.js +169 -169
- package/src/backend/lib/llm-client.js +176 -176
- package/src/backend/lib/model-context-windows.js +82 -82
- package/src/backend/lib/native-task-control.js +217 -217
- package/src/backend/lib/native-task-history-index.js +475 -475
- package/src/backend/lib/native-task-history-reader.js +526 -526
- package/src/backend/lib/native-task-messages.js +457 -457
- package/src/backend/lib/native-task-registry.js +325 -325
- package/src/backend/lib/native-task-runtime.js +242 -242
- package/src/backend/lib/native-task-trace.js +440 -440
- package/src/backend/lib/native-task-transcript.js +393 -393
- package/src/backend/lib/prompt-registry.js +166 -166
- package/src/backend/lib/runtime-config.js +121 -121
- package/src/backend/lib/sdk-session-stream.js +143 -143
- package/src/backend/lib/sdk-turn-stream.js +16 -16
- package/src/backend/lib/store-scope.js +131 -131
- package/src/backend/lib/task-identity.js +104 -104
- package/src/backend/lib/task-state-projection.js +58 -58
- package/src/index.js +7 -7
- package/src/sdk-wave-a.ts +1 -1
- package/src/sdk-wave-b.ts +1 -1
- package/src/sdk-wave-c.ts +1 -1
- package/src/sdk-wave-d.ts +1 -1
- package/src/sdk-wave-e.ts +1 -1
|
@@ -1,144 +1,144 @@
|
|
|
1
|
-
// AI analyzer adapter interface (TASK-005 + TASK-008).
|
|
2
|
-
// Each adapter implements the same shape so the orchestrator can swap implementations.
|
|
3
|
-
//
|
|
4
|
-
// analyzeCommitBatch({ project, commits, contextPack }) -> { changes: [...] }
|
|
5
|
-
// validateOutput(output) -> { valid: boolean, errors: string[] }
|
|
6
|
-
//
|
|
7
|
-
// All adapters MUST return objects that pass validateOutput. The orchestrator never
|
|
8
|
-
// writes drafts to disk unless the output validates.
|
|
9
|
-
|
|
10
|
-
const fs = require('fs');
|
|
11
|
-
const path = require('path');
|
|
12
|
-
|
|
13
|
-
function isString(v) { return typeof v === 'string'; }
|
|
14
|
-
function isNonEmptyString(v) { return isString(v) && v.length > 0; }
|
|
15
|
-
function isStringArray(v) { return Array.isArray(v) && v.every(isString); }
|
|
16
|
-
function isObject(v) { return v && typeof v === 'object' && !Array.isArray(v); }
|
|
17
|
-
|
|
18
|
-
function normalizeKnowledgeLanguage(value) {
|
|
19
|
-
return value === 'en-US' ? 'en-US' : 'zh-CN';
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function languageName(value) {
|
|
23
|
-
return normalizeKnowledgeLanguage(value) === 'en-US' ? 'English' : 'Simplified Chinese';
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const changeEntrySchema = {
|
|
27
|
-
commit: isNonEmptyString,
|
|
28
|
-
classification: (v) => ['new-feature', 'existing-feature-update', 'bug-fix', 'refactor', 'infrastructure', 'test-only', 'docs-only'].includes(v),
|
|
29
|
-
developmentIntent: isNonEmptyString,
|
|
30
|
-
goalImpact: isNonEmptyString,
|
|
31
|
-
evidence: isStringArray,
|
|
32
|
-
proposedOps: (v) => Array.isArray(v) && v.every(op => isObject(op) && isNonEmptyString(op.op) && isNonEmptyString(op.path)),
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
function validateCommitBatchOutput(output) {
|
|
36
|
-
const errors = [];
|
|
37
|
-
if (!isObject(output)) { errors.push('output is not an object'); return { valid: false, errors }; }
|
|
38
|
-
if (!Array.isArray(output.changes)) { errors.push('missing or invalid: changes'); return { valid: false, errors }; }
|
|
39
|
-
for (let i = 0; i < output.changes.length; i++) {
|
|
40
|
-
const c = output.changes[i];
|
|
41
|
-
if (!isObject(c)) { errors.push(`change[${i}] is not an object`); continue; }
|
|
42
|
-
for (const [key, check] of Object.entries(changeEntrySchema)) {
|
|
43
|
-
if (!(key in c)) { errors.push(`change[${i}] missing: ${key}`); continue; }
|
|
44
|
-
if (!check(c[key])) errors.push(`change[${i}].${key} is invalid`);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return { valid: errors.length === 0, errors };
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// ---- claude-code-agent: real LLM via Anthropic-compatible API ----
|
|
51
|
-
//
|
|
52
|
-
// This adapter calls an Anthropic Messages API (real Anthropic or any
|
|
53
|
-
// compatible proxy such as api.minimaxi.com/anthropic). The model returns
|
|
54
|
-
// JSON that the KB orchestrator validates against the existing schemas.
|
|
55
|
-
//
|
|
56
|
-
// The adapter is intentionally minimal: it does ONE call per commit batch
|
|
57
|
-
// and asks the model to return a strict JSON object matching the schema.
|
|
58
|
-
// Validation happens in `validateOutput`; if the model misbehaves, the run
|
|
59
|
-
// is marked failed and the user can re-trigger.
|
|
60
|
-
|
|
61
|
-
const { completeJson } = require('./llm-client');
|
|
62
|
-
|
|
63
|
-
const COMMIT_SYSTEM = `You are a senior software architect reviewing a batch of git commits. For each commit, decide what useful knowledge should be recorded in the project's knowledge base. Respond with a single JSON object matching the schema in the user message. Do not invent file paths. Cite the provided evidence (context pack entries) whenever possible. Summarize the user's development intent; do not preserve raw prompts. Do not propose operations that would write outside changes/, modules/, README.md, GOAL.md, or ARCHITECTURE.md.`;
|
|
64
|
-
|
|
65
|
-
function buildCommitUser({ project, commits, contextPack }) {
|
|
66
|
-
const outputLanguage = languageName(project && project.knowledgeLanguage);
|
|
67
|
-
const ctx = (contextPack && contextPack.entries || []).slice(0, 30).map(e => `- ${e.path}: ${(e.summary || '').slice(0, 200)}`).join('\n');
|
|
68
|
-
const list = (commits || []).map(c => `- full=${c.hash} | short=${c.short || c.hash.slice(0,7)} | ${c.date || ''} | ${c.author || ''} | ${c.subject || ''}`).join('\n');
|
|
69
|
-
return `Project slug: ${project.slug}
|
|
70
|
-
Knowledge output language: ${normalizeKnowledgeLanguage(project.knowledgeLanguage)} (${outputLanguage})
|
|
71
|
-
|
|
72
|
-
Pending commits (chronological order, oldest first). For each line, the "full=" value is the COMPLETE 40-character commit hash; you MUST copy that exact value into the JSON "commit" field:
|
|
73
|
-
${list || '(no commits)'}
|
|
74
|
-
|
|
75
|
-
Context pack excerpts:
|
|
76
|
-
${ctx || '(no context pack available)'}
|
|
77
|
-
|
|
78
|
-
Return a JSON object of the form:
|
|
79
|
-
{
|
|
80
|
-
"changes": [
|
|
81
|
-
{
|
|
82
|
-
"commit": string, // FULL 40-char commit hash copied from the input
|
|
83
|
-
"classification": "new-feature" | "existing-feature-update" | "bug-fix" | "refactor" | "infrastructure" | "test-only" | "docs-only",
|
|
84
|
-
"developmentIntent": string, // concise summary of the user's request or prompt intent; never raw prompt logs
|
|
85
|
-
"goalImpact": string, // one short sentence
|
|
86
|
-
"evidence": [string], // paths cited from the context pack
|
|
87
|
-
"proposedOps": [{ "op": "create-file" | "append-section" | "update-section", "path": string, "fromTemplate"?: string }]
|
|
88
|
-
}
|
|
89
|
-
]
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
Constraints:
|
|
93
|
-
- All human-readable natural language string values MUST be written in ${outputLanguage}. Keep JSON keys, enum values, file paths, and commit hashes exactly as specified.
|
|
94
|
-
- One entry per commit in the input list, in the same order.
|
|
95
|
-
- "commit" MUST be the full 40-character hash from the input (the value after "full="), NOT the short hash.
|
|
96
|
-
- proposedOps[].path MUST be a relative path under changes/ or modules/, or exactly README.md, GOAL.md, or ARCHITECTURE.md. Goal and architecture edits require human review.
|
|
97
|
-
- Do not include any text outside the JSON object.`;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const claudeCodeAgent = {
|
|
101
|
-
id: 'claude-code-agent',
|
|
102
|
-
name: 'Claude Code Agent (Anthropic-compatible)',
|
|
103
|
-
description: 'Real LLM through an Anthropic-compatible Messages API. AI profiles can reuse this implementation with different model providers.',
|
|
104
|
-
async analyzeCommitBatch({ project, commits, contextPack }) {
|
|
105
|
-
const user = buildCommitUser({ project, commits, contextPack });
|
|
106
|
-
const r = await completeJson({ system: COMMIT_SYSTEM, user, maxTokens: 4096, profileId: project && project.aiProfileId });
|
|
107
|
-
if (!r.parsed) {
|
|
108
|
-
console.error(`[claude-code-agent] LLM did not return valid JSON. text head: ${r.text.slice(0, 500)} ... text tail: ${r.text.slice(-500)}`);
|
|
109
|
-
const e = new Error(`LLM returned no parseable JSON (${r.parseError && r.parseError.message || 'no output'})`);
|
|
110
|
-
e.llmText = r.text;
|
|
111
|
-
throw e;
|
|
112
|
-
}
|
|
113
|
-
// Sanity log: how many changes did the LLM return, and what do the commits look like?
|
|
114
|
-
const changes = (r.parsed && r.parsed.changes) || [];
|
|
115
|
-
console.log(`[claude-code-agent] parsed ${changes.length} changes; first change: ${JSON.stringify(changes[0]).slice(0, 300)}`);
|
|
116
|
-
return r.parsed;
|
|
117
|
-
},
|
|
118
|
-
validateOutput(output) {
|
|
119
|
-
return validateCommitBatchOutput(output);
|
|
120
|
-
},
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
const ADAPTERS = {
|
|
124
|
-
'claude-code-agent': claudeCodeAgent,
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
function getAdapter(id) {
|
|
128
|
-
return ADAPTERS[id] || null;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function listAdapters() {
|
|
132
|
-
return Object.values(ADAPTERS).map(a => ({
|
|
133
|
-
id: a.id,
|
|
134
|
-
name: a.name,
|
|
135
|
-
description: a.description || null,
|
|
136
|
-
}));
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
module.exports = {
|
|
140
|
-
ADAPTERS,
|
|
141
|
-
getAdapter,
|
|
142
|
-
listAdapters,
|
|
143
|
-
validateCommitBatchOutput,
|
|
144
|
-
};
|
|
1
|
+
// AI analyzer adapter interface (TASK-005 + TASK-008).
|
|
2
|
+
// Each adapter implements the same shape so the orchestrator can swap implementations.
|
|
3
|
+
//
|
|
4
|
+
// analyzeCommitBatch({ project, commits, contextPack }) -> { changes: [...] }
|
|
5
|
+
// validateOutput(output) -> { valid: boolean, errors: string[] }
|
|
6
|
+
//
|
|
7
|
+
// All adapters MUST return objects that pass validateOutput. The orchestrator never
|
|
8
|
+
// writes drafts to disk unless the output validates.
|
|
9
|
+
|
|
10
|
+
const fs = require('fs');
|
|
11
|
+
const path = require('path');
|
|
12
|
+
|
|
13
|
+
function isString(v) { return typeof v === 'string'; }
|
|
14
|
+
function isNonEmptyString(v) { return isString(v) && v.length > 0; }
|
|
15
|
+
function isStringArray(v) { return Array.isArray(v) && v.every(isString); }
|
|
16
|
+
function isObject(v) { return v && typeof v === 'object' && !Array.isArray(v); }
|
|
17
|
+
|
|
18
|
+
function normalizeKnowledgeLanguage(value) {
|
|
19
|
+
return value === 'en-US' ? 'en-US' : 'zh-CN';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function languageName(value) {
|
|
23
|
+
return normalizeKnowledgeLanguage(value) === 'en-US' ? 'English' : 'Simplified Chinese';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const changeEntrySchema = {
|
|
27
|
+
commit: isNonEmptyString,
|
|
28
|
+
classification: (v) => ['new-feature', 'existing-feature-update', 'bug-fix', 'refactor', 'infrastructure', 'test-only', 'docs-only'].includes(v),
|
|
29
|
+
developmentIntent: isNonEmptyString,
|
|
30
|
+
goalImpact: isNonEmptyString,
|
|
31
|
+
evidence: isStringArray,
|
|
32
|
+
proposedOps: (v) => Array.isArray(v) && v.every(op => isObject(op) && isNonEmptyString(op.op) && isNonEmptyString(op.path)),
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
function validateCommitBatchOutput(output) {
|
|
36
|
+
const errors = [];
|
|
37
|
+
if (!isObject(output)) { errors.push('output is not an object'); return { valid: false, errors }; }
|
|
38
|
+
if (!Array.isArray(output.changes)) { errors.push('missing or invalid: changes'); return { valid: false, errors }; }
|
|
39
|
+
for (let i = 0; i < output.changes.length; i++) {
|
|
40
|
+
const c = output.changes[i];
|
|
41
|
+
if (!isObject(c)) { errors.push(`change[${i}] is not an object`); continue; }
|
|
42
|
+
for (const [key, check] of Object.entries(changeEntrySchema)) {
|
|
43
|
+
if (!(key in c)) { errors.push(`change[${i}] missing: ${key}`); continue; }
|
|
44
|
+
if (!check(c[key])) errors.push(`change[${i}].${key} is invalid`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return { valid: errors.length === 0, errors };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// ---- claude-code-agent: real LLM via Anthropic-compatible API ----
|
|
51
|
+
//
|
|
52
|
+
// This adapter calls an Anthropic Messages API (real Anthropic or any
|
|
53
|
+
// compatible proxy such as api.minimaxi.com/anthropic). The model returns
|
|
54
|
+
// JSON that the KB orchestrator validates against the existing schemas.
|
|
55
|
+
//
|
|
56
|
+
// The adapter is intentionally minimal: it does ONE call per commit batch
|
|
57
|
+
// and asks the model to return a strict JSON object matching the schema.
|
|
58
|
+
// Validation happens in `validateOutput`; if the model misbehaves, the run
|
|
59
|
+
// is marked failed and the user can re-trigger.
|
|
60
|
+
|
|
61
|
+
const { completeJson } = require('./llm-client');
|
|
62
|
+
|
|
63
|
+
const COMMIT_SYSTEM = `You are a senior software architect reviewing a batch of git commits. For each commit, decide what useful knowledge should be recorded in the project's knowledge base. Respond with a single JSON object matching the schema in the user message. Do not invent file paths. Cite the provided evidence (context pack entries) whenever possible. Summarize the user's development intent; do not preserve raw prompts. Do not propose operations that would write outside changes/, modules/, README.md, GOAL.md, or ARCHITECTURE.md.`;
|
|
64
|
+
|
|
65
|
+
function buildCommitUser({ project, commits, contextPack }) {
|
|
66
|
+
const outputLanguage = languageName(project && project.knowledgeLanguage);
|
|
67
|
+
const ctx = (contextPack && contextPack.entries || []).slice(0, 30).map(e => `- ${e.path}: ${(e.summary || '').slice(0, 200)}`).join('\n');
|
|
68
|
+
const list = (commits || []).map(c => `- full=${c.hash} | short=${c.short || c.hash.slice(0,7)} | ${c.date || ''} | ${c.author || ''} | ${c.subject || ''}`).join('\n');
|
|
69
|
+
return `Project slug: ${project.slug}
|
|
70
|
+
Knowledge output language: ${normalizeKnowledgeLanguage(project.knowledgeLanguage)} (${outputLanguage})
|
|
71
|
+
|
|
72
|
+
Pending commits (chronological order, oldest first). For each line, the "full=" value is the COMPLETE 40-character commit hash; you MUST copy that exact value into the JSON "commit" field:
|
|
73
|
+
${list || '(no commits)'}
|
|
74
|
+
|
|
75
|
+
Context pack excerpts:
|
|
76
|
+
${ctx || '(no context pack available)'}
|
|
77
|
+
|
|
78
|
+
Return a JSON object of the form:
|
|
79
|
+
{
|
|
80
|
+
"changes": [
|
|
81
|
+
{
|
|
82
|
+
"commit": string, // FULL 40-char commit hash copied from the input
|
|
83
|
+
"classification": "new-feature" | "existing-feature-update" | "bug-fix" | "refactor" | "infrastructure" | "test-only" | "docs-only",
|
|
84
|
+
"developmentIntent": string, // concise summary of the user's request or prompt intent; never raw prompt logs
|
|
85
|
+
"goalImpact": string, // one short sentence
|
|
86
|
+
"evidence": [string], // paths cited from the context pack
|
|
87
|
+
"proposedOps": [{ "op": "create-file" | "append-section" | "update-section", "path": string, "fromTemplate"?: string }]
|
|
88
|
+
}
|
|
89
|
+
]
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
Constraints:
|
|
93
|
+
- All human-readable natural language string values MUST be written in ${outputLanguage}. Keep JSON keys, enum values, file paths, and commit hashes exactly as specified.
|
|
94
|
+
- One entry per commit in the input list, in the same order.
|
|
95
|
+
- "commit" MUST be the full 40-character hash from the input (the value after "full="), NOT the short hash.
|
|
96
|
+
- proposedOps[].path MUST be a relative path under changes/ or modules/, or exactly README.md, GOAL.md, or ARCHITECTURE.md. Goal and architecture edits require human review.
|
|
97
|
+
- Do not include any text outside the JSON object.`;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const claudeCodeAgent = {
|
|
101
|
+
id: 'claude-code-agent',
|
|
102
|
+
name: 'Claude Code Agent (Anthropic-compatible)',
|
|
103
|
+
description: 'Real LLM through an Anthropic-compatible Messages API. AI profiles can reuse this implementation with different model providers.',
|
|
104
|
+
async analyzeCommitBatch({ project, commits, contextPack }) {
|
|
105
|
+
const user = buildCommitUser({ project, commits, contextPack });
|
|
106
|
+
const r = await completeJson({ system: COMMIT_SYSTEM, user, maxTokens: 4096, profileId: project && project.aiProfileId });
|
|
107
|
+
if (!r.parsed) {
|
|
108
|
+
console.error(`[claude-code-agent] LLM did not return valid JSON. text head: ${r.text.slice(0, 500)} ... text tail: ${r.text.slice(-500)}`);
|
|
109
|
+
const e = new Error(`LLM returned no parseable JSON (${r.parseError && r.parseError.message || 'no output'})`);
|
|
110
|
+
e.llmText = r.text;
|
|
111
|
+
throw e;
|
|
112
|
+
}
|
|
113
|
+
// Sanity log: how many changes did the LLM return, and what do the commits look like?
|
|
114
|
+
const changes = (r.parsed && r.parsed.changes) || [];
|
|
115
|
+
console.log(`[claude-code-agent] parsed ${changes.length} changes; first change: ${JSON.stringify(changes[0]).slice(0, 300)}`);
|
|
116
|
+
return r.parsed;
|
|
117
|
+
},
|
|
118
|
+
validateOutput(output) {
|
|
119
|
+
return validateCommitBatchOutput(output);
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const ADAPTERS = {
|
|
124
|
+
'claude-code-agent': claudeCodeAgent,
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
function getAdapter(id) {
|
|
128
|
+
return ADAPTERS[id] || null;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function listAdapters() {
|
|
132
|
+
return Object.values(ADAPTERS).map(a => ({
|
|
133
|
+
id: a.id,
|
|
134
|
+
name: a.name,
|
|
135
|
+
description: a.description || null,
|
|
136
|
+
}));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
module.exports = {
|
|
140
|
+
ADAPTERS,
|
|
141
|
+
getAdapter,
|
|
142
|
+
listAdapters,
|
|
143
|
+
validateCommitBatchOutput,
|
|
144
|
+
};
|