selftune 0.1.0 → 0.1.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/CHANGELOG.md +11 -0
- package/LICENSE +21 -0
- package/README.md +62 -5
- package/bin/selftune.cjs +3 -1
- package/cli/selftune/constants.ts +0 -6
- package/cli/selftune/dashboard.ts +176 -0
- package/cli/selftune/evolution/evolve.ts +31 -20
- package/cli/selftune/evolution/propose-description.ts +2 -3
- package/cli/selftune/evolution/rollback.ts +1 -1
- package/cli/selftune/evolution/validate-proposal.ts +3 -4
- package/cli/selftune/grading/grade-session.ts +18 -62
- package/cli/selftune/index.ts +21 -0
- package/cli/selftune/ingestors/codex-rollout.ts +1 -1
- package/cli/selftune/ingestors/opencode-ingest.ts +2 -2
- package/cli/selftune/init.ts +25 -36
- package/cli/selftune/last.ts +138 -0
- package/cli/selftune/observability.ts +1 -1
- package/cli/selftune/status.ts +318 -0
- package/cli/selftune/types.ts +1 -1
- package/cli/selftune/utils/llm-call.ts +8 -57
- package/dashboard/index.html +1119 -0
- package/package.json +32 -3
- package/skill/SKILL.md +19 -14
- package/skill/Workflows/Doctor.md +2 -9
- package/skill/Workflows/Evals.md +8 -17
- package/skill/Workflows/Evolve.md +5 -11
- package/skill/Workflows/Grade.md +5 -10
- package/skill/Workflows/Ingest.md +16 -34
- package/skill/Workflows/Initialize.md +32 -34
- package/skill/Workflows/Rollback.md +3 -10
- package/skill/Workflows/Watch.md +2 -9
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
* Shared LLM call utility.
|
|
3
3
|
*
|
|
4
4
|
* Provides a unified interface for calling LLMs via agent subprocess
|
|
5
|
-
* (claude/codex/opencode)
|
|
6
|
-
*
|
|
5
|
+
* (claude/codex/opencode). Extracted from grade-session.ts so other
|
|
6
|
+
* modules can reuse the same calling logic.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { readFileSync, writeFileSync } from "node:fs";
|
|
10
10
|
import { tmpdir } from "node:os";
|
|
11
11
|
import { join } from "node:path";
|
|
12
12
|
|
|
13
|
-
import { AGENT_CANDIDATES
|
|
13
|
+
import { AGENT_CANDIDATES } from "../constants.js";
|
|
14
14
|
|
|
15
15
|
// ---------------------------------------------------------------------------
|
|
16
16
|
// Agent detection
|
|
@@ -126,67 +126,18 @@ export async function callViaAgent(
|
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
// ---------------------------------------------------------------------------
|
|
130
|
-
// Call LLM via direct Anthropic API
|
|
131
|
-
// ---------------------------------------------------------------------------
|
|
132
|
-
|
|
133
|
-
/** Call LLM via direct Anthropic API. Returns raw text. */
|
|
134
|
-
export async function callViaApi(systemPrompt: string, userPrompt: string): Promise<string> {
|
|
135
|
-
const apiKey = process.env.ANTHROPIC_API_KEY ?? "";
|
|
136
|
-
if (!apiKey) {
|
|
137
|
-
throw new Error(
|
|
138
|
-
"ANTHROPIC_API_KEY not set. Use --use-agent to grade via your " +
|
|
139
|
-
"installed Claude Code / Codex / OpenCode subscription instead.",
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
const payload = {
|
|
144
|
-
model: MODEL,
|
|
145
|
-
max_tokens: 2000,
|
|
146
|
-
system: systemPrompt,
|
|
147
|
-
messages: [{ role: "user", content: userPrompt }],
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
const resp = await fetch(API_URL, {
|
|
151
|
-
method: "POST",
|
|
152
|
-
headers: {
|
|
153
|
-
"Content-Type": "application/json",
|
|
154
|
-
"x-api-key": apiKey,
|
|
155
|
-
"anthropic-version": "2023-06-01",
|
|
156
|
-
},
|
|
157
|
-
body: JSON.stringify(payload),
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
if (!resp.ok) {
|
|
161
|
-
const body = await resp.text();
|
|
162
|
-
throw new Error(`API error ${resp.status}: ${body}`);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
const data = await resp.json();
|
|
166
|
-
let raw = "";
|
|
167
|
-
for (const block of data.content ?? []) {
|
|
168
|
-
if (block.type === "text") raw += block.text ?? "";
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
return raw;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
129
|
// ---------------------------------------------------------------------------
|
|
175
130
|
// Unified dispatcher
|
|
176
131
|
// ---------------------------------------------------------------------------
|
|
177
132
|
|
|
178
|
-
/**
|
|
133
|
+
/** Call LLM via agent subprocess. Returns raw text. */
|
|
179
134
|
export async function callLlm(
|
|
180
135
|
systemPrompt: string,
|
|
181
136
|
userPrompt: string,
|
|
182
|
-
|
|
183
|
-
agent?: string,
|
|
137
|
+
agent: string,
|
|
184
138
|
): Promise<string> {
|
|
185
|
-
if (
|
|
186
|
-
|
|
187
|
-
throw new Error("Agent must be specified when mode is 'agent'");
|
|
188
|
-
}
|
|
189
|
-
return callViaAgent(systemPrompt, userPrompt, agent);
|
|
139
|
+
if (!agent) {
|
|
140
|
+
throw new Error("Agent must be specified for callLlm");
|
|
190
141
|
}
|
|
191
|
-
return
|
|
142
|
+
return callViaAgent(systemPrompt, userPrompt, agent);
|
|
192
143
|
}
|